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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RARankin
Forum Newbie
Posts: 2
Joined: Mon Jan 31, 2005 4:24 pm
Location: Morrisville, NC

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

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's correct, you will need to remove the path data from the filename.
RARankin
Forum Newbie
Posts: 2
Joined: Mon Jan 31, 2005 4:24 pm
Location: Morrisville, NC

Post 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
Post Reply