views:

635

answers:

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>
+3  A: 

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

Anti Veeranna
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
SeanJA
+1  A: 
echo "Picture=" . $_POST['picture'] . "<br/>";

The POST variable

$_POST['picture']

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

Steerpike
A: 

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.

Igoru
A: 

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.

metha
A: 

try adding

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

before

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