homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

File upload issue

 7:39 am on Jan 12, 2012 (gmt 0)

I have file upload issue in IE9 and Firefox where as it works fine in old IE browsers. It works fine in IE9 compatible mode but doesn't work in its own default mode.

My code is very straight forward which i am using for long time:

<form name="myform" id="myform" action="" method="post" enctype="multipart/form-data">




 7:54 am on Jan 12, 2012 (gmt 0)

Your code will not run in ANY browser because there is NO form action. See: [php.net...]


 11:15 am on Jan 12, 2012 (gmt 0)

Thanks for the reply. I have tried with action but still it is not working in IE9 and firefox and still working quite fine in IE8 or lesser.

<form name="myform" id="myform" action="listededit.php" method="post" enctype="multipart/form-data">


 1:43 pm on Jan 12, 2012 (gmt 0)

Turn up error reporting for PHP, and also look for some hints at what might be happening on the PHP side by printing out the value of

Once you know the error code, you can backtrack to the source of the problem: [php.net...]


 1:46 pm on Jan 12, 2012 (gmt 0)

>> Your code will not run in ANY browser because there is NO form action.

Actually, not specifying a form's action should default to submitting the form to the current page. My guess is the processing of this upload is handled at the same URI, and therefore it was working as expected?

Still good practice to fill the action property with a value.


 4:52 pm on Jan 12, 2012 (gmt 0)

still it is not working in IE9

AFAIK a server side process will never be browser dependent. If something is not working in a particular browser, there may be invalid code or Javascript mucking up the works. It's something in your page output before you try to submit.

That being said,
1) Validate the page [validator.w3.org]. If the page is a result of PHP output and a direct URL won't work, get on the page, view the source, and use the direct input tab on the validator.

2) When you say "won't work" does that mean "won't submit?" If so there may be some layout method rendering the submit button inaccessible. Check out the page in FireFox and use the FireBug extension to scope that out.

3) Related, use input type="submit" if you're not already. Input type="button" or <button> have no inherent actions on their own and require Javascript to work.

4) As mentioned, add programming server side to debug. Error trapping is often overlooked, even if it's never used when everything is working. Example,

if ($some_condition) {
$err = try_to_do_something();
if ($err) { print $err; }
else { print $success; }

You can build this into anything you write with something like this

// $debug=1; // uncomment to turn on debugging

// Then throughout your code,

if ($debug) {
print "input value is $this and $that<br>";

Another real world example is the handling of PHP mail [webmasterworld.com]. Usually just "mail(...)" works, but when it doesn't it's useful to do

if ! (mail(...)) {
// Mail returns true or false.
// If false, you will wind up here, print error message


 5:15 pm on Jan 12, 2012 (gmt 0)

File is not being uploaded in IE9 default mode. There is no javascript it is simple html file upload control. $_FILES['img1']['error'] returns 0 which means there is no error but why file is not being uploaded I am unable to get the issue in IE9 and if I turn it to compatible mode it works. Is there anyone else facing the same issue in IE9?


 6:15 pm on Jan 12, 2012 (gmt 0)

>> returns 0

How are you verifying that no file was successfully uploaded? I'd find it unlikely for PHP to return 0 and not at least have it in the temp directory.


 11:11 am on Jan 13, 2012 (gmt 0)

Many thanks for replies. I got the issue. I was using old image types as:

$_FILES['img1']['type']=="image/pjpeg" || $_FILES['img1']['type']=="image/x-png"

pjpeg and x-png are not supported in IE9 and firefox.


 1:46 pm on Jan 13, 2012 (gmt 0)

Cool glad you were able to figure it out.

Also, for easy scalability, you could include an array of allowable MIME types instead of writing a separate condition for each:

$allowable = array('image/bmp', 'image/gif', 'image/jpeg', 'image/png');

if(in_array($_FILES['img1']['type'], $allowable)) {
// ...process
} else {
// ...reject


 8:36 pm on Jan 13, 2012 (gmt 0)

eelixduppy's idea is an excellent one. The W3C states:

"There is no limit in the Web specifications to the graphical formats that can be used on the Web. You just need a MIME type so that the format is labelled correctly for transfer across the Web, and so that a suitable viewer (if one exists) can be located at the other end.

In practice, certain formats are more widely understood than others; certain formats are more suited to one type of graphical data than another; so you should make an informed choice about what format to use."

The 3 (arguably) most prevalent and browser supported image formats do not include .bmp and do include .jpg, .png and perhaps .gif

This is code I've used for years it includes a few other application supported formats:


I observe that the W3C is also big on svg as per the above link.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved