homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

delete link after filename

 9:31 am on Feb 24, 2009 (gmt 0)

I have used the PHP4 script here [webmasterworld.com...] to display a list of files in a folder, but can't figure out how to get a delete link working after each filename.

I know I have to use unlink, but I have no idea how to modify the script.

How is it done?


nick patrick

 3:44 pm on Feb 24, 2009 (gmt 0)

paste the script here


 5:39 pm on Feb 24, 2009 (gmt 0)

index.php is:

<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" id="submit" />
$dir = opendir('upload/');
echo '<ul>';

while ($read = readdir($dir))

if ($read!='.' && $read!='..')
echo '<li><a href="upload/'.$read.'">'.$read.'</a></li>';


echo '</ul>';


and upload.php (in same directory) is:

$target_path = "upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";


 10:41 am on Feb 25, 2009 (gmt 0)

You can pass another link with a specific parameter to it so you can differentiate on the server end that you want to delete the file if that parameter is passed. So for example right after this:
echo '<li><a href="upload/'.$read.'">'.$read.'</a>';
you could add
echo ' <a href="delete_file_script.php?name=' . $read '">Delete '.$read.'</a></li>';

When the delete_file_script.php is invoked you check for the name parameter:
if( isset($_GET['name']) ) {
$filename = '/fullpath/upload/' . basename($_GET['name']);
if(file_exists($filename) ) {
Or you can process everything within the same script by changing the href parameter in the <a> tag.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved