predator Posted March 15, 2007 Share Posted March 15, 2007 Hi i have been looking on the forums for a while now and cannot find the answer i need. i have the following upload script $target = "uploaded/".$_FILES['fileUp']['name']; if(move_uploaded_file($_FILES['fileUp']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } and the following html submit form <form enctype="multipart/form-data" method="POST" action="Upload.php"> <br /> <input name="fileUp" type="file"/> <br /> <br /> <input type="submit" value="Upload File"/> </form> however when i hit submit to take it to the upload page i get the errors of Notice: Undefined index: fileUp in c:\inetpub\wwwroot\Sites\TNL New\uploader\Upload.php on line 3 Notice: Undefined index: fileUp in c:\inetpub\wwwroot\Sites\TNL New\uploader\Upload.php on line 5 i just cannot work out why. the file input box is called fileUp but get it still gives me this error please can anyone help i have been racking me brain over this for ages and from what i can see it should just work. thanks for help in advance regards Mark Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 That is just a notice, it does not mean anything other than stating that fileUp is not an index of the array $_FILES. The reason is you have no logic to check if the form was submitted. I would do a check such as: if (isset($_FILES['fileUp'])) { $target = "uploaded/".$_FILES['fileUp']['name']; if(move_uploaded_file($_FILES['fileUp']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } }else { ?> <form enctype="multipart/form-data" method="POST" action="Upload.php"> <input name="fileUp" type="file"/> <input type="submit" value="Upload File"/> </form> <?php } I would probably just hide the notices if it is working via http://us3.php.net/manual/en/function.error-reporting.php Notices do not necessarily mean anything. It is the warning and FATAL ERRORs that you have to watch out for. Quote Link to comment Share on other sites More sharing options...
predator Posted March 15, 2007 Author Share Posted March 15, 2007 thanks for the swift reply however when i run my script it does come up as Sorry, there was a problem uploading your file. why would it come up with this if all i can see is that the information is correct if i echo $_FILES['uploadedfile']['name']; that also comes up as nothing like nothing has even been passed through from the form. regards Mark Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 Why did you change that index to uploadedfile instead of fileUp, it should stay the same. Quote Link to comment Share on other sites More sharing options...
predator Posted March 15, 2007 Author Share Posted March 15, 2007 right just checked and made sure they are all uploadedfile and also the file input is uploadedfile as well but still with a simple check it shows that no file is being passed from the form to the actual upload script. regards Mark Quote Link to comment Share on other sites More sharing options...
predator Posted March 15, 2007 Author Share Posted March 15, 2007 not to worry sorted it my self Quote Link to comment 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.