Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

delete link after filename



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

5+ Year Member

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)

5+ Year Member

paste the script here


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

5+ Year Member

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)

WebmasterWorld Senior Member 5+ Year Member

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.


Featured Threads

Hot Threads This Week

Hot Threads This Month