I want edit_file.php to allow users to edit or delete any existing file’s record. The delete code works 10 out 10 but the edit doesn’t.
What I am trying to do is to check if a new file has been submitted, if so update the file information to uploads table and then move it to its final destination – using the upload_id(to replace the old file).
If the file wasn’t uploaded, I just need to update description column.
Here’s the code:-- Thanks in advance–
If(isset($_POST[‘submitted’])){
//check for a file
If(isset($FILES[‘upload’])){
//check for a description
If(!empty($_POST[‘description’])){
$d=”’”.escape_data($_POST[‘description’]).”’”;
}else{
$d=NULL;
}
//Update file record.
$query = "UPDATE uploads SET file_name='{$_FILES['upload']['name']}', file_size={$_FILES['upload']['size']}, file_type='{$_FILES['upload']['name']}', description='$d' WHERE upload_id=$uid";
$result= mysql_query($query);
// Move the file over.
if (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/$upload_id")) {
echo '<p>File has been uploaded!</p>';
} else {// File could not be moved
echo '<p><font color="red">The File could not be moved.</font></p>';
}//end move_uploaded_file
} else { // If the query did not run OK.-- end
echo '<p><font color="red">Your file could not be processed due to a system error. We apologize for any inconvenience.</font></p>';
// Print the query and invoke the mysql_error() function to debug.
echo '<p><font color="red">' . mysql_error() . '<br /><br />
Query: ' . $query . '</font></p>'; // Debugging message.
} // End of if (isset($the_file)...
// End of the submitted conditional.