i am trying to uplaod a file but i get the following errors
Notice: Undefined index: uploadFile in /nfs/mntI4/projectsite/J.K.Childs/file1.php on line 8
Notice: Undefined index: uploadFile in /nfs/mntI4/projectsite/J.K.Childs/file1.php on line 9
although i can see the lines where the errors should be i cannot understand what they are. can anyone spot what is wrong with this code
here is the code from my website
<form action="file1.php" method="post">
Document to upload (please only upload microsoft word documents others will not work): <input type="file" name="upload">
<input type="submit" name="upload2" value="uploadFile">
</form>
here is the code from my php form
<html>
<head>
<title>Php document for uploading files</title>
</head>
<body>
<?php
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")
?>
</body>
</html>
can anyone spot what might be wrong
upload function not working properly
Moderator: General Moderators
-
bluebirdjc
- Forum Newbie
- Posts: 3
- Joined: Tue Jan 27, 2009 10:53 am
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
Re: upload function not working properly
when you run that page, it automatically is trying to upload the file because you have the function move_uploaded_file called at the end of it. The Notices come from the fact that you are trying access an array element that does not exist. In easier terms:
You open that page, it goes though, top to bottom, and reaches the "move_uploaded_file" function. Your code:
says "take the variable $_FILES['uploadFile']['tmp_name'] and put it in the uploads folder and save it as $_FILES['uploadFile']['name'] (another variable name)"
Well, you see, nobody has said what the variables $_FILES['uploadFile']['tmp_name'] and $_FILES['uploadFile']['name'] are! If you have not submitted a form with them in it then PHP won't do it automagically and you did not set them anywhere in your script so they don't exist!
And what is why you get your error. take a look at the functions isset() and empty() in the manual for ways around this delema you are finding yourself in.
You open that page, it goes though, top to bottom, and reaches the "move_uploaded_file" function. Your code:
Code: Select all
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], "../uploads/{$_FILES['uploadFile'] ['name']}")Well, you see, nobody has said what the variables $_FILES['uploadFile']['tmp_name'] and $_FILES['uploadFile']['name'] are! If you have not submitted a form with them in it then PHP won't do it automagically and you did not set them anywhere in your script so they don't exist!
And what is why you get your error. take a look at the functions isset() and empty() in the manual for ways around this delema you are finding yourself in.