I have a site that people can upload files to. This part i have succeeded in. the file is entered into the database and to an uploads folder on the server. I have an administration page where the files can be viewed from the database and downloaded from the server and i have a "delete" option. I figured out how to have to file deleted from the database but cannot figure out how to remove it from the server as well. Here is the code for uploading the files, if it helps:
$query = "INSERT INTO uploads (file_name, file_size, file_type, description, upload_date, mem_ids)
VALUES ('{$FILES['upload']['name']}', {$FILES['upload']['size']},
'{$FILES['upload']['type']}', '$d', NOW(), '{$SESSION['mem_id']}')";
$result = @ ($query);
if ($result) {
$extension = explode ('.', $_FILES['upload']['name']);
$uid = mysql_insert_id();
$filename = $uid . '.' . $extension[1];
if (move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/$filename")) {
echo '<span class="errors">The file has been uploaded.</span>';
} else {
echo'<span class="errors">The file could not be moved. Its size may be too large.</span>';
$query = "DELETE FROM uploads WHERE upload_id = $uid";
$result = @mysql_query ($query);
}
} else {
echo '<span class="errors">Your submission could not be processed due to a system error. Our apologies.</span>';
}
mysql_close();
}
}
?>