DreamHost Web Hosting
Discussion Forum


Forums
   >> Programming
*Threaded Mode

Subject problem uploading a file with PHP  
Posted bychauzer (DH New User )
Posted on12/02/06 09:27 PM



i have a upload field and hit the upload button, and it posts to a php file

in my php file, im performing this check:

is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']

but it keeps returning false.. any ideas why? im using PHP 5 here on dreamhost



Subject Re: problem uploading a file with PHP new [re: chauzer]  
Posted byrlparker (DH Pooh-Bah)
Posted on12/02/06 11:00 PM



In reply to:

im performing this check:

is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']

but it keeps returning false.. any ideas why? im using PHP 5 here on dreamhost


PHP5 on Dreamhost is compiled with register_globals set to off. As such, you either need to "globablize" the $HTTP_POST_FILES variables, or use a "superglobal" instead.

From the zend.com manual on PHP 5 regarding reserved variables:

In reply to:

HTTP File upload variables: $_FILES

Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_FILES.

An associative array of items uploaded to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_FILES; to access it within functions or methods, as you do with $HTTP_POST_FILES.

$HTTP_POST_FILES contains the same information, but is not an autoglobal. (Note that $HTTP_POST_FILES and $_FILES are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_FILES and $HTTP_POST_FILES arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.


You might also find the Handlilng file uploads section of the PHP Manual (and links there!), as well as the Dreamhost Wiki article on Register_Globals to be helpful. Good Luck!

--rlparker




*Threaded Mode
Jump to