Jump to content

[SOLVED] List directory, and allow deletion of listed files


jsschmitt

Recommended Posts

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...

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.