Jump to content

delete a file within a directory using a link-PHP


alexander007

Recommended Posts

Is there a way to delete a file within a directory using a link?

 

I have a script that will list all the files in a directory and, in the output, I'd like to create a link next to each file that says "delete This file" and then will delete the file from the /dir

 

filename1.jpg delete file

filename2.jpg delete file

filename3.jpg delete file

filename4.jpg delete file

 

I try but when I click on the delete button I delete all the files of the /dir...

<?php

function showContent($path){


   if ($handle = opendir($path))
   {
       $up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
       echo "<thead><tr><th colspan='3'><center>RECURSOS</center></th></tr></thead>";

       while (false !== ($file = readdir($handle)))
       {
           if ($file != "." && $file != "..")
           {
               $fName = $file;
               $file = $path.'/'.$file;
               if(is_file($file)) {
                   echo "<tr><td><img src='../media/images/file2.gif' width='16' height='16' alt='file'/> <a href='".$file."'>".$fName."</a></td>"
                            ."<td align='right'>".date ('d-m-Y H:i:s', filemtime($file))."</td>"
                            ."<td align='right'>".filesize($file)." bytes</td>"
						."<td align='right'><a href='".unlink($fName)."'>Borrar</a></td></tr>";
               } elseif (is_dir($file)) {
                   print "<tr><td colspan='2'><img src='style/dir2.gif' width='16' height='16' alt='dir'/> <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
               }
           }
       }

       closedir($handle);
   }	

}
$actpath = "../recursos/";

?>

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.