Can anyone help me out.

I'm having a few problems with an upload script I've tried to write.

Basically I want to only allow users to upload gif/jpg with a file size less than 120KB.

I've written the following bit of validation but it seems to work in the opposite way to I would expect. Does anyone have any ideas??

$_FILE looks like this:

Array ( [userfile] => Array ( [name] => latenight.jpg [type] => image/pjpeg [tmp_name] => /tmp/phpxsJn7R [error] => 0 [size] => 33796 ) )

The code I am using is this:

if(($userfile_type != "image/gif") || ($userfile_type != "image/pjpeg") || ($userfile_size > 122880)){
	echo 'ERROR: The file could not be uploaded. This could be because:<br/>';
	echo '- The file was an incorrect filetype, please supply the image in either GIF or JPEG formats.<br/>';
	echo '- The file was larger than 120KB.<br/>';
} else {

echo 'Upload';
}

    well, i've never seen funky notation like this:

    Array ( [userfile] => Array ( [name] => latenight.jpg [type] => image/pjpeg [tmp_name] => /tmp/phpxsJn7R [error] => 0 [size] => 33796 ) )

    maybe your if statement should check against $userfile['type'] and not $userfile_type?

      Originally posted by sneakyimp
      maybe your if statement should check against $userfile['type'] and not $userfile_type?

      i suspect furious5 has register_globals turned on, this creates global variables from the $FILES array. from the manual:


      When register_globals is turned on in php.ini, additional variables are available. For example, $userfile_name will equal $_FILES['userfile']['name'], $userfile_type will equal $_FILES['userfile']['type'], etc. Keep in mind that as of PHP 4.2.0, register_globals defaults to off. It's preferred to not rely on this directive.

        Originally posted by devinemke
        i suspect furious5 has register_globals turned on, this creates global variables from the $FILES array. from the manual:

        But $FILES is still defined (hence the dumped array). By inspection of that dumped array, one can figure out that the type would be in $_FILES['userfile']['type'].

          Originally posted by Weedpacket
          But $FILES is still defined (hence the dumped array). By inspection of that dumped array, one can figure out that the type would be in $FILES['userfile']['type'].

          yes, however i was just pointing out that with register_globals turned ON the original validation code should work. i suppose the most obvious explanation of furious5's problem would be that he/she has register_globals OFF and is trying to run code that assumes that it is ON.

            Write a Reply...