Page 1 of 1

Problem with $_FILES['userfile']['name'] and IE

Posted: Mon Jan 31, 2005 4:40 pm
by RARankin
I have been having an issue lately with file uploads behaving differently under different browsers. I the problem originally showed itself in phpBB, however it is not restricted to its use.

When a file is uploaded and stored in php's temp folder the filename, size, etc is saved in the $_FILES['*']['*'] array. The issue I am having is that $_FILES['userfile']['name'] is not showing the same data from browser to browser, more specifically:

Using IE (6.0.2900.2180.xpsp_sp2_rtm.040803-2158):

$_FILES['userfile']['name'] -> C:\Documents and
Settings\User\Desktop\image.jpg

Using Firefox (1.0):

$_FILES['userfile']['name'] -> image.jpg

I had recently updated to a dev version of PHP (4.3.11-dev) because of a bug in the current version (4.3.10) while trying to compile in the GD library from an external source. Because of that update I attributed the error to the dev version of PHP and submitted a bug report to php ( http://bugs.php.net/bug.php?id=31757 ). PHP then told me it was a bug in IE and to report it to them.

My question is, has this error shown up anywhere else? If so, what version of php and IE where you using? I'm guessing I can solve it by parsing the filename reported by IE and removing everything before the last slash..?

Andrew

Posted: Mon Jan 31, 2005 5:59 pm
by feyd
that's correct, you will need to remove the path data from the filename.

Posted: Mon Jan 31, 2005 7:49 pm
by RARankin
My Fix:

Code: Select all

if ($pos = strrpos($HTTP_POST_FILESї'fileupload']ї'name'], "&quote;))
      {
         $filename = substr($HTTP_POST_FILESї'fileupload']ї'name'], $pos+1);
      }
      else
      {
         $filename = $HTTP_POST_FILESї'fileupload']ї'name'];
      }
Andrew