File: /var/www/nclive/technc/upload_file.php_25jan19
<?php
include 'header.php';
include 'sidebar.php';
include 'top_header.php';
global $wpdb;
?>
<style>
.total_ques_div
{
background-color: white;
border-color: #C8D5E0;
border-image: none;
border-style: solid;
border-width: 1px 1px 2px;
color: #1E598E;
font-weight: bold;
padding: 8px 10px;
text-decoration: none;
}
.form-table td
{
padding:0px !important;
}
.extLink{
text-decoration: none;
cursor: pointer;
}
.fancybox-skin
{ margin-left: 400px!important;
width: 500px!important;
}
.form-table td {
padding: 5px !important;
font-size:12px !important;
}
</style>
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<?php
// $currentDir = getcwd();
// $uploadDirectory = "/upload_file/";
// $uploadPath = $currentDir . $uploadDirectory . basename($fileName);
if (isset($_POST['submit'])) {
$errors = []; // Store all foreseen and unforseen errors here
$fileExtensions = ['jpeg','jpg','png']; // Get all the file extensions
$fileName = $_FILES['myfile']['name'];
$fileSize = $_FILES['myfile']['size'];
$fileTmpName = $_FILES['myfile']['tmp_name'];
$fileType = $_FILES['myfile']['type'];
$fileExtension = strtolower(end(explode('.',$fileName)));
// $entity=$_POST['exam'];
$target_dir="/var/www/html/technc/uploads/";
if(!is_dir($target_dir))
{
mkdir($target_dir, 0777, true);
$target_file = $target_dir . $fileName;
$didUpload = move_uploaded_file($_FILES['myfile']["tmp_name"],$target_file);
} else {
$target_file = $target_dir . $fileName;
$didUpload = move_uploaded_file($_FILES['myfile']["tmp_name"],$target_file);
}
// if (! in_array($fileExtension,$fileExtensions)) {
// $errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
// }
// if ($fileSize > 2000000) {
// $errors[] = "This file is more than 2MB. Sorry, it has to be less than or equal to 2MB";
// }
// if (empty($errors)) {
// $didUpload = move_uploaded_file($fileTmpName,$target_dir);
// if ($didUpload) {
// echo "The file " . basename($fileName) . " has been uploaded";
// } else {
// echo "An error occurred somewhere. Try again or contact the admin";
// }
// } else {
// foreach ($errors as $error) {
// echo $error . "These are the errors" . "\n";
// }
// }
// }
$id=$_REQUEST['exam'];
$title=$_REQUEST['title'];
$insertquery="insert into sp_exam_uploads set exam_id='$id', title='$title', upload_file='$fileName'";
$sql=$db->prepare($insertquery);
if($sql->execute()){
$message = "<font style='color:green; float:left;'><h3> Insert successfully</h3></font>";
}else{
$message = "<font style='color:red; float:left;'><h3> error</h3></font>";
}
}
?>
<main id="main-container">
<div class="content content-narrow">
<div class="row">
<div class="col-lg-12">
<h2 class="content-heading">Select Exam</h2>
<div class="block">
<div class="block-header">
<ul class="block-options">
<li>
<button type="button"><i class="si si-settings"></i></button>
</li>
</ul>
<h4class="block-title"><?php echo $message ?></h4>
</div>
<div class="block-content block-content-narrow">
<form class="js-validation-bootstrap form-horizontal" method="post" enctype="multipart/form-data" >
<div class="form-group">
<label class="col-md-2 control-label" for="val-select2">Select Exam </label>
<div class="col-md-10">
<select class="js-select2 form-control" name="exam" style="width: 100%;">
<?php
$sql = $db->prepare("SELECT exam_id,exam_name FROM sp_exam ORDER by exam_name ASC");
$sql->execute();
?><option>--Select Exam--</option><?php
while($row=$sql->fetch(PDO::FETCH_ASSOC))
{
?>
<option value="<?php echo $row['exam_id']; ?>"><?php echo $row['exam_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="val-email">Title:<span class="text-danger">*</span></label>
<div class="col-md-7">
<input class="form-control" type="text" name="title" id="title" placeholder="" required>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="val-password">Upload a File:<span class="text-danger">*</span></label>
<div class="col-md-7">
<input class="form-control" type="file" name="myfile" >
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button class="btn btn-lg btn-primary" name="submit" type="submit">Upload File</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="content content-narrow">
<div class="row">
<div class="col-lg-12">
<h2 class="content-heading">Upload List </h2>
<div class="table-responsive">
<table id="payu" class="table table-striped table-bordered dt-responsive nowrap" style="width: 100%; cellspacing: 0; f">
<thead>
<tr class="danger">
<th>S.no</th>
<th>Exam Name</th>
<th>Title</th>
<th>Path</th>
</tr>
</thead>
<tbody id="payu_list"></tbody>
</table>
<script type="text/javascript">
jQuery.ajax({
url: '<?php echo ADMIN_URL; ?>/upload_file_data.php',
data: {
format: 'json'
},
error: function() {
$('#payu').html('<p>An error has occurred</p>');
},
dataType: 'json',
success: function(data) {
console.log(data);
var Data = '';
var j=0;
var msg= "'Are you sure'";
for (var i = 0; i < data.length; i++) {
var k=parseInt(i+1);
Data += '<tr><td>'+k+'</td>'
// if(data[i].status == 1){
// Data += '<td><a style="cursor:pointer;" id='+data[i].id+','+data[i].status+' onclick="confirm('+msg+') && update(id)"><span id="status">Active</span></a></td>';
// } else if(data[i].status == 0) {
// Data += '<td><a style="cursor:pointer;" id='+data[i].id+','+data[i].status+' onclick="confirm('+msg+') && update(id)"><span id="status">Deactive</span></a></td>';
// }
// Data += '<td> <button name="update" class="btn btn-info" onclick="selectData('+data[i].id+')" data-toggle="tooltip" title="Edit this exam">Edit </button></td>';
Data += '<td>'+ data[i].exam_name + '</td><td>'+data[i].title+'</td><td><a href="'+data[i].file_path+'" target="_blank">'+data[i].file_path+'</td></a></tr>';
}
document.getElementById('payu_list').innerHTML = Data;
jQuery('#payu').dataTable( {
"bPaginate": true,
"responsive": true,
"iDisplayLength": 20,
"lengthMenu": [[20, 50, 100, 500, 1000], [20, 50, 100, 500, 1000]]
});
},
type: 'GET'
});
</script>
</div>
</div>
</div>
</div>
</main>
<?php include 'footer.php'; ?>