Slightly different task this time round, I wish to delete files inside a specific directory with the click of a drop down option (Which calls the file name) and then followed this by a submit button click.
<?php
$myFile = "testFile.txt";
unlink($myFile);
?>
I am under the idea that the above code is what I need. However I make the “testFile.txt” is replaced with something along the lines of:
<?php $myFile = ?><html>Dropdown code here to list all files in directory</html><?php ; unlink($myFile);
?>
I’m still editing and chopping the snippet so sorry if the response takes a while.
Edit: I was wondering if you could help me with creating it so that it is a drop down box of all the files uploaded into the directory /uploads/ so I can delete them without searching.
Thanks in advance everybody.
edit:
Ok, So after some help I have achieved this so far:
<?php
$path = "uploads/";
$handle = opendir($path);
while ($file = readdir($handle)) {
if (substr($file,0,1) != ".") {
echo "<option value ='$file'></option>";
}
}
closedir($handle);
?>
However this won’t display the files in the options, I know im missing something here. I used your guys resources and:
Here’s one way – it may not be perfect, I haven’t tested it
dir will get you a listing of files in a directory, you can use that to populate an options list in PHP, and echo it out to your HTML page.
PHP:
HTML:
Then you can get the file from the $_POST or $_GET array after the user submits the form.
Hope this helps.