How to update an upload file?

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.




           


$FILES[‘upload’] should be $_FILES[‘upload’] on row 3.

Test the upload for errors; $_FILES[‘upload’][‘error’].

Though unsure about this, $_FILES might be set even if a file was not uploaded. It has an error assignment for when no file is uploaded, but it may be that the file field needs to explicitly have input for the variable to be defined.

Though unsure about this, $_FILES might be set even if a file was not uploaded. It has an error assignment for when no file is uploaded, but it may be that the file field needs to explicitly have input for the variable to be defined.

yes it does so we can manipulate it!


if($_FILES['upload']['error'] == 4) {
// no file has been uploaded - therefore ignore it
} else {
// a new file has been uploaded so do something
}