require_once 'includes/header.php'; if($_POST['status']=='study_material') { $filename = time().$_FILES['image']['name']; // destination of the file on the server $destination = '../uploads/study_material/' . $filename; // get the file extension $extension = pathinfo($filename, PATHINFO_EXTENSION); // the physical file on a temporary uploads directory on the server $file = $_FILES['image']['tmp_name']; $size = $_FILES['image']['size']; if (!in_array($extension, ['jpg', 'pdf', 'docx', 'jpeg', 'png'])) { echo ''; } elseif ($_FILES['image']['size'] > 100000000) { // file shouldn't be larger than 1Megabyte echo ''; } else { // move the uploaded (temporary) file to the specified destination if (move_uploaded_file($file, $destination)) { $sql = "INSERT INTO `study_material` (`id`, `timestamp`, `description`, `file`) VALUES (NULL, CURRENT_TIMESTAMP, '".$_POST['title']."', '".$filename."')"; if (mysqli_query($con, $sql)) { echo ''; } } else { echo ''; } } } if($_GET['action']=='del') { if(file_exists("../uploads/study_material/".$_GET['file'])) unlink("../uploads/study_material/".$_GET['file']); $con->query("DELETE FROM study_material where id = '".$_GET['id']."'"); echo ''; } ?>