When trying to access the $_FILES
array, PHP returns the error
"Undefined index: picture".
In my php.ini
file, File Uploads
are turned on, and any user can write in the /tmp
directory. In the HTML form, enctype is set to "multipart/form-data"
. Interestingly enough, the basename for the uploaded file prints so I believe that PHP has actually seen the file, but has some problem uploading it.
Can someone provides suggestions on potential solutions to this problem? By the way, I am using PHP5.
Snippets from PHP File
echo "Picture=" . $_POST['picture'] . "<br/>";
$uploadedPic = $_FILES['picture']['tmp_name'];
HTML Form
<form action="PHPFile.php" method="post" enctype="multipart/form-data">
<p> Picture </p>
<input type = "file" id="picture" name="picture"/>
</form>
On what line do you get that warning? If it is the one with $_POST['picture']
, then its logical, you wont find uploaded file data in $_POST
, it is in $_FILES
echo "Picture=" . $_POST['picture'] . "<br/>";
The POST variable
$_POST['picture']
doesn't exist, so yes, it's going to give an undefined error.
lol, a previous poster said that restarting their server fixed it. i did the same, and for some reason it works. i made no code changes, and IIS resets didn't work either. it required a reboot of the computer itself. that's about 2hrs completely lost.
What level or error reporting are you using?
error_reporting(E_ALL)
will turn on full reporting and might give you a hint.
As previously described, do a print of $_FILES
with var_dump()
or print_r()
to see information for your file.
I can't comment, so I'll say it here.
MAN, this echo will print the file name! It works! He said it works.
Interestingly enough, the basename for the uploaded file prints so I believe that PHP has actually seen the file[...]
A good hint: try to var_dump
the $_FILES
and add here it's contents. You may have an error because the file is too big, or some other useful information.
try adding
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
before
<input type = "file" id="picture" name="picture"/>