jsschmitt Posted March 25, 2009 Share Posted March 25, 2009 Here is what i have: $path = "access/"; $narray=array(); $dir_handle = @opendir($path) or die("Unable to open $path"); echo "Directory Listing of $path<br/><br/>"; $i=0; while($file = readdir($dir_handle)) { if($file != '.' && $file != '..') { //echo "<a href='$path/$file'>$file</a>"; $narray[$i]=$file; $i++; } } sort($narray); for($i=0; $i<sizeof($narray); $i++) { echo "<a href='".$url.$path.$narray[$i]."' target='main'>".$narray[$i]."</a>"; } //closing the directory closedir($dir_handle); And that creates a directory listing (that links to the files in an iframe) without any issues. What I want to do is add a "delete" button after each listed file that allows you to delete the file, but can't figure out how to "call" the specific url into a variable. For an idea of the application of this, visit my site: www.anomymage.com and enter dir as the command... Link to comment https://forums.phpfreaks.com/topic/151125-solved-list-directory-and-allow-deletion-of-listed-files/ Share on other sites More sharing options...
WolfRage Posted March 25, 2009 Share Posted March 25, 2009 Use realpath() to create the correct path to the file, and then delete the file with the unlink() function. Link to comment https://forums.phpfreaks.com/topic/151125-solved-list-directory-and-allow-deletion-of-listed-files/#findComment-793912 Share on other sites More sharing options...
jsschmitt Posted March 25, 2009 Author Share Posted March 25, 2009 How would I call the URL from the page... in another page? i.e. index.php lists the directory and links, and the delete button sends the url to delete.php Link to comment https://forums.phpfreaks.com/topic/151125-solved-list-directory-and-allow-deletion-of-listed-files/#findComment-793934 Share on other sites More sharing options...
WolfRage Posted March 26, 2009 Share Posted March 26, 2009 You will need to pass the radio button value which will be the realpath() of the file using your form and $_POST. Link to comment https://forums.phpfreaks.com/topic/151125-solved-list-directory-and-allow-deletion-of-listed-files/#findComment-794542 Share on other sites More sharing options...
jsschmitt Posted March 26, 2009 Author Share Posted March 26, 2009 Thanks! Got it figured out! $path = "access/"; $narray=array(); $dir_handle = @opendir($path) or die("Unable to open $path"); echo "Directory Listing of $path<br/><br/>"; echo "<table>"; $i=0; while($file = readdir($dir_handle)) { if($file != '.' && $file != '..') { //echo "<a href='$path/$file'>$file</a>"; $narray[$i]=$file; $i++; } } sort($narray); for($i=0; $i<sizeof($narray); $i++) { echo "<tr><td><a href='".$url.$path.$narray[$i]."' target='main'>".$narray[$i]."</a></td><td><FORM action='delete.php' method='post' name='delete'><input type='hidden' value='".$path.$narray[$i]."' name='url'><input type='submit' value='Delete' id='entcom' /></FORM></td></tr>"; } //closing the directory closedir($dir_handle); Link to comment https://forums.phpfreaks.com/topic/151125-solved-list-directory-and-allow-deletion-of-listed-files/#findComment-794737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.