View Single Post
  #57 (permalink)  
Old 04-29-2008, 11:54 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Filesystem Object in PHP

is_uploaded_file() is available only in versions of PHP 3 after PHP 3.0.16, and in versions of PHP 4 after 4.0.2. If you are stuck using an earlier version, you can use the following function to help protect yourself:

PHP Code:
<?php
/* Userland test for uploaded file. */
function is_uploaded_file_4_0_2($filename
{
    if (!
$tmp_file get_cfg_var('upload_tmp_dir')) {
        
$tmp_file dirname(tempnam(''''));
    }
    
$tmp_file .= '/' basename($filename);
    
/* User might have trailing slash in php.ini... */
    
return (ereg_replace('/+''/'$tmp_file) == $filename);
}

/* This is how to use it, since you also don't have
 * move_uploaded_file() in these older versions: */
if (is_uploaded_file_4_0_2($HTTP_POST_FILES['userfile'])) {
    
copy($HTTP_POST_FILES['userfile'], "/place/to/put/uploaded/file");
} else {
    echo 
"Possible file upload attack: filename '$HTTP_POST_FILES[userfile]'.";
}
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Reply With Quote