dtyson2000 Posted January 6, 2008 Share Posted January 6, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/84738-file-upload-script-fine-until-edit/ Share on other sites More sharing options...
JJohnsenDK Posted January 6, 2008 Share Posted January 6, 2008 yeah you should check if the $_FILES exits else dont update that field in the database. Quote Link to comment https://forums.phpfreaks.com/topic/84738-file-upload-script-fine-until-edit/#findComment-431932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.