5

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>
5
  • 2
    have you tried var_dumping your $_FILES? Commented Aug 28, 2009 at 10:57
  • 1
    Are you by any chance using Javascript to serialize your form? Commented Aug 28, 2009 at 10:57
  • 3
    is post_max_size and upload_max_filesize in your php.ini set to a large enough value? Commented Aug 28, 2009 at 11:04
  • I used print_r to print the contents of the $_FILES array, and it printed an empty array. For some awkward reason, it works now. All I had to do was restart the server. I did not change any settings whatsoever, and the file is less than 40KB. Thank you for all of your help! Commented Aug 29, 2009 at 20:57
  • 4
    I recently just had this issue and it was because I forgot to add enctype="multipart/form-data" to the form declaration, I see you didn't but in case anyone else gets here. Commented Dec 5, 2012 at 22:35

6 Answers 6

6

On what line do you get that warning? If it is the one with $_POST['picture'], then it's logical, you won't find uploaded file data in $_POST, it is in $_FILES.

Sign up to request clarification or add additional context in comments.

1 Comment

On a sidenote.... you will want to check if the $_SERVER['REQUEST_METHOD'] == 'POST' if you are just uploading a file in your form and not submitting any other data
1
echo "Picture=" . $_POST['picture'] . "<br/>";

The POST variable

$_POST['picture']

doesn't exist, so yes, it's going to give an undefined error.

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

-2

try adding

<input type="hidden" name="MAX_FILE_SIZE" value="30000" />

before

<input type = "file" id="picture" name="picture"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.