Hi All,
You guys have helped me to develop an upload script previously but now I wanted to allow users to delete files as well.
I can create a delete script easily enough for the database value but I struggle when it comes to deleting the file from one of server directories.
My delete script so far is…
[php]<?php
// check ‘id’ value is set
if(isset($_GET[‘d’])) {
}
// check all our variables are set
if (isset($_POST[“del”]))
{
// call database…
$sql = “DELETE FROM tbl_documents WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ AND file_name =” .$_GET[‘d’] ;
if ($db->query($sql) === TRUE) { // will return true if successful else it will return false
echo "<script>location.href='index.php'</script>";
}
else {
// if the database was not updated then inform user
echo "<div class='alert alert-danger alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>×</span><span class='sr-only'>Close</span></button>
<strong>Error!</strong> File not deleted!!!</div>";
}
}
?>
[/php]
My html is along these lines…
[php]
Are you sure you wish to delete this file?
[/php]
My files are located in a folder “www.website.com/directory/pages/documents/uploads/”