views:

343

answers:

3

I'm trying to get a file uploaded through a PHP script, but my $_FILES array is always empty? My $_POST data entry for the file HTML input element has the filename...Just no file is created on my local system.

I've verified write access to the temp folder and explicity set it. I've checked phpinfo() to make sure file uploads are enabled, and they are.

What could be preventing this? Would mod_rewrite cause anything?

Thanks!

+7  A: 

Are you defining the enctype in your form ?

<form method="post" enctype="multipart/form-data">

No file will be uploaded if you don't set it.

Damien MATHIEU
+2  A: 

Does the form have the right enctype?

enctype="multipart/form-data"
Ólafur Waage
+8  A: 

When you have the proper enctype(<form method="post" enctype="multipart/form-data">), then check the errno variable in $_FILES, there are various possible causes for a failure. Typical is MAX_FILE_SIZE being exceeded.

http://php.net/manual/en/features.file-upload.errors.php

Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].

UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

etc.

Vinko Vrsalovic
print_r($_FILES) results in array()...So unfortunately, that data is not available. I do however have enctype="multipart/form-data" in my form.
Omega
I had a closer look - oddly on a lower resolution screen to make it even funnier - and there was a typo in my code.This is even more ironic considering some of the first few solutions I found while looking this up said "watch out for typos". So...Simply put...There's so much to line up here, watch out for typos! Thanks for all the kicks in the pants everyone :)
Omega