Jump to content

File Upload Script - Fine Until EDIT


dtyson2000

Recommended Posts

Hi All...

 

I've used a script that I found (very simple one) to upload files to a server via a handy-dandy form. The form also has other text fields - no problem. Everything goes into my database including the file name and the file uploads to the directory I need.

 

Here's the problem:

 

Suppose I realize that I've made a spelling error in one of those text fields. I click to edit the record and make the change, submit and "where did the filename that was attached to that record go??"

 

If I need to actually edit the record and change the file, no problems. What I see happening is that, if I don't select a file to upload (because I may not need to), the script is attempting to upload a file without one actually being chosen, then wiping the filename out of the database.

 

Here's the form item:

<input type= 'file' name='event_file' value='$event_file'>

 

Here's the function:

function upload(){
  $target_path = "../upload/";

  $target_path = $target_path . basename( $_FILES['event_file']['name']);
  $_FILES['event_file']['tmp_name'];

  if(move_uploaded_file($_FILES['event_file']['tmp_name'], $target_path)) {
      echo "The file ".  basename( $_FILES['event_file']['name']). 
      " has been uploaded";
      $event_file = basename( $_FILES['event_file']['name']);
  } else{
      echo "There was an error uploading the file, please try again!";
  }
}

 

I'm using the standard UPDATE table SET column='updated column'... in the database.

 

Should I be using ISSET or something where the value of the file input in the form is concerned? If you need more code, let me know. Thanks, in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/84738-file-upload-script-fine-until-edit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.