Forum Moderators: coopster
I know I have to use unlink, but I have no idea how to modify the script.
How is it done?
<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" />
</form>
</div>
<div>
<ul>
<?php
$dir = opendir('upload/');
echo '<ul>';while ($read = readdir($dir))
{
if ($read!='.' && $read!='..')
{
echo '<li><a href="upload/'.$read.'">'.$read.'</a></li>';
}
}
echo '</ul>';
closedir($dir);
?>
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!";
}
When the delete_file_script.php is invoked you check for the name parameter:
<?php
if( isset($_GET['name']) ) {
$filename = '/fullpath/upload/' . basename($_GET['name']);
if(file_exists($filename) ) {
unlink($filename);
}
}
?>
Or you can process everything within the same script by changing the href parameter in the <a> tag.