[SOLVED] File upload -> doesn't work with 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

raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

[SOLVED] File upload -> doesn't work with IE?

Post by raging radish »

I've bashed together a script to upload .jpg files. It works perfectly with Linux/Mozilla/Galeon. It works under Windows with Firefox. It doesn't work under Windows and IE 6.

Anybody have a clue as to why?
Last edited by raging radish on Mon Dec 06, 2004 6:36 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Make sure you set the enctype in your form tag.

Code: Select all

<form enctype="multipart/form-data"....
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

That's the first thing I checked and it looks ok to me. Here it is for reference.

Code: Select all

<form enctype="multipart/form-data" action="<?php print $_SERVER&#1111;'PHP_SELF']?>" method="post">
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="204800" />
Image 1 <input type="file" name="fupload"/><br/>
<input type="submit" value="Upload"/>
</p>
</form>
The only real difference between this and the example shown on php.net is that this page refers to itself, rather than another file/page. Is it possible that there's an issue with the page referring to itself?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

There shouldnt be a problem, check the source code of the page to see what value is in the action attribute after php has parsed the page.
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

After php has parsed the page:

Code: Select all

<form enctype="multipart/form-data" action="/file_upload.php" method="post">
The source is the same in IE and Firefox (Windows)

Edit: I should probably add that "file_upload.php" is the correct name.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Try removing the forward slash in action.
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

agtlewis wrote:Try removing the forward slash in action.
That thought occurred to me but I can't see how I can change it since php puts it there with the PHP_SELF reference.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

$ThisURI = $_SERVER&#1111;'PHP_SELF'];
str_replace('', '/', $ThisURI);

echo $ThisURI;
That forward slash just irks me:(

I have never used one in a page that posts to itself, and it wouldn't surprise me if ie became confused by it.
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

I don't think it's the slash causing the issue. I rewrote the page to call the php script on a separate page and the source parses like this:

Code: Select all

<form enctype="multipart/form-data" action="upload.php" method="post">
Still doesn't work in IE, fine in the other browsers.

slowly going insane :-/
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Maybe it's the forward slashes in the form then...

Try changing

Code: Select all

Image 1 <input type="file" name="fupload"/><br/> 
<input type="submit" value="Upload"/>
to

Code: Select all

Image 1 <input type="file" name="fupload"><br/> 
<input type="submit" value="Upload">
While still keeping the other forward slash removed as well.
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

Still no joy.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Do you have any form tags that aren't closed above that one? Did you properly close that form tag? Can you post the source code for the entire page please?

I know for a fact this code works... this is something I wrote a long time ago.

Code: Select all

<h2>Upload New File</h2>
    <form enctype="multipart/form-data" action="account_manager.php?mode=10" method="post">
      <table class="box" cellpadding="0" cellspacing="0">
<?php
if ($error != '') // someone goofed somewhere
  &#123;
?>
        <tr>
          <td class="bline" colspan="2" align="center" style="color: #9B202C;"><b>ERROR: </b><?php echo $error; ?></td>
        </tr>
<?php
&#125;
?>
      <tr>
        <td width="18%" class="bline" style="text-align: right;"><b>File Name:</b></td>
        <td width="82%" class="blline" ><input class="upload" name="userfile" type="file"></td>
      </tr>
      <tr>
        <td colspan="2" class="bline" style="text-align: center;" ><b>File Description</b></td>
      </tr>
      <tr>
        <td colspan="2" style="text-align: center;"><textarea name="description" class="services"></textarea></td>
      </tr>
      <tr>
        <td colspan="2">Please give us a detailed description of this file.  Include
        information such as what this file is, how you would like it used, what webpage you would like it on, 
        what if any changes need to be made etc.</td>
      </tr>
      <tr>
        <td colspan="2" class="bline" style="text-align: right;">
          <input type="hidden" name="upload_file" value="true">
          <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size_bytes; ?>">
          <input class="button" type="submit" value="Transfer File">
        </td>
      </tr>
    </table>
  </form>
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

Here it is. All the tags seem to be closed properly.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Image upload</title>
<LINK href="sn/ss/ss.css" type=text/css rel=stylesheet>
</head>
<body>

<!--DON'T CHANGE THIS-->
<div id="leftcontent">
<?php
include("sn/sn_include_ex.txt");
?>
</div>
<!--OK, YOU CAN CHANGE IT NOW-->

<div id="rightcontent">

<h3 align="left">Image Upload Page</h3>
<p>Use this page to upload your images.<br/>
<ul>
<li>Image files must be .jpg.
<li>Maximum filesize (each) is 2 megabytes.
</ul><br/>

<form enctype="multipart/form-data" action="upload.php" method="post">
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="204800">
Image 1 <input type="file" name="fupload"><br/>
<input type="submit" value="Upload">
</p>
</form>
</div>
</body>
</html>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

First, what exactly happens? Not "it doesn't work", but does it hang? Does it give you an error? etc..

Secondly, paste ALL relevant code (preferably in

Code: Select all

tags)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

There was an <h3 tag that was not closed, and some other miscellaneous things that I fixed.

Try this.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<title>Image upload</title> 
<LINK href="sn/ss/ss.css" type=text/css rel=stylesheet> 
</head> 
<body> 

<!--DON'T CHANGE THIS--> 
<div id="leftcontent"> 
<?php 
include("sn/sn_include_ex.txt"); 
?> 
</div> 
<!--OK, YOU CAN CHANGE IT NOW--> 

<div id="rightcontent"> 

<h3> align="left">Image Upload Page</h3> 
<p>Use this page to upload your images.</p>
<ul> 
<li>Image files must be .jpg.</li>
<li>Maximum filesize (each) is 2 megabytes.</li>
</ul><br/>

<form enctype="multipart/form-data" action="upload.php" method="post"> 
<p> 
<input type="hidden" name="MAX_FILE_SIZE" value="204800"> 
Image 1 <input type="file" name="fupload"><br/> 
<input type="submit" value="Upload"> 
</p> 
</form> 
</div> 
</body> 
</html>
Post Reply