Problem uploading a file with PHP

software development

#1

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


#2

[quote]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[/quote]
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:

[quote]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.[/quote]
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! :slight_smile:

–rlparker