Help to delete uploaded files
Posted: Sun May 30, 2010 6:30 pm
Hello! I made a script to allow trusted members of my site to upload files and store on the server. The script allows the member to upload a file, it then sets the permission and stores it in the designated folder and displays the contents of the folder as links as well as displays the upload form to allow another upload. The script also updates a database that I will use for another purpose. This script is working perfect. My problem is I am trying to create a script that will display a checkbox next to the file links that are in the folder and allow the user to check the box and then delete that file from the server. The script will have to go through the checkbox array and then delete the files that are checked. I've been trying to use the unlink function, but I am lost. Any help would be appreciated. Below is the code for the upload incase you need it. It is the first part of a 3 step process. But again, all this works fine and I just need to delete a file with a user selected checkbox.
Thank you,
Jerry
Thank you,
Jerry
Code: Select all
// Define the full path to your folder from root
$path = "/../upload/";
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" || $file == "upload.php" || $file == "index2.php")
continue;
echo "<a href=\"$file\">$file</a><br />";
}
closedir($dir_handle);
?>
<h5>Upload new file to upload directory</h5>
<form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form>