alexander007 Posted October 24, 2007 Share Posted October 24, 2007 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... Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/ Share on other sites More sharing options...
kenrbnsn Posted October 24, 2007 Share Posted October 24, 2007 Please post your code between tags. Ken Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/#findComment-377395 Share on other sites More sharing options...
phpQuestioner Posted October 24, 2007 Share Posted October 24, 2007 try this tutorial: http://www.tizag.com/phpT/filedelete.php Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/#findComment-377397 Share on other sites More sharing options...
alexander007 Posted October 24, 2007 Author Share Posted October 24, 2007 <?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/"; ?> Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/#findComment-377398 Share on other sites More sharing options...
kenrbnsn Posted October 24, 2007 Share Posted October 24, 2007 You're deleting the files as you create the links with "unlink($fName)". The link should name the file to delete and pass it to a script to delete. Ken Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/#findComment-377400 Share on other sites More sharing options...
phpQuestioner Posted October 24, 2007 Share Posted October 24, 2007 it could be passed with a query string - could it not? like this: deletepage.php?myFile=filename1.jpg Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/#findComment-377402 Share on other sites More sharing options...
alexander007 Posted October 25, 2007 Author Share Posted October 25, 2007 I think of that But I dont want to have the script that delete the files on other file... Link to comment https://forums.phpfreaks.com/topic/74662-delete-a-file-within-a-directory-using-a-link-php/#findComment-377403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.