Page 1 of 2

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

Posted: Sun Dec 05, 2004 6:37 pm
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?

Posted: Sun Dec 05, 2004 6:53 pm
by Benjamin
Make sure you set the enctype in your form tag.

Code: Select all

<form enctype="multipart/form-data"....

Posted: Sun Dec 05, 2004 7:23 pm
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?

Posted: Sun Dec 05, 2004 7:31 pm
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.

Posted: Sun Dec 05, 2004 7:44 pm
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.

Posted: Sun Dec 05, 2004 7:53 pm
by Benjamin
Try removing the forward slash in action.

Posted: Sun Dec 05, 2004 8:05 pm
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.

Posted: Sun Dec 05, 2004 8:07 pm
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.

Posted: Sun Dec 05, 2004 8:34 pm
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 :-/

Posted: Sun Dec 05, 2004 8:40 pm
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.

Posted: Sun Dec 05, 2004 8:48 pm
by raging radish
Still no joy.

Posted: Sun Dec 05, 2004 8:50 pm
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>

Posted: Sun Dec 05, 2004 8:56 pm
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>

Posted: Sun Dec 05, 2004 8:57 pm
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)

Posted: Sun Dec 05, 2004 9:01 pm
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>