|
|
Question : PHP/XHTML file upload not working with ie or firefox
|
|
|
|
I have been asked to create a form that allows users to upload a picture. It works great in Safari, Chrome, and Opera. Fails in ie and firefox. The browser itself is refusing to send anything.
Here is my code:
<?php session_start(); echo "<?xml version = '1.0' encoding = 'utf-8' ?>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Picture upload Page --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head profile = 'http://www.w3.org/2005/10/profile'> <title>Commando Pic Upload</title> <link rel = 'icon' type = 'image/png' href = '../img/cc.png' /> <?php if (isset ($_SESSION['special'])) { $uploaded = false; $stored = false; $error = ""; ini_set ("max_input_time", 300); if ($_POST['submit']) { if ($_FILES['picFile']['error'] > 0) { $error = "Error Code: " . $_FILES['picFile']['error'] . "<br />\n"; $error .= "Something unusual happened during the upload. The image never arrived.<br />\n"; } else if ($_FILES['picFile']['size'] > (2048 * 1024)) { $error = "Your file is too big. (" . ($_FILES['picFile']['size'] / 1024) . "KB)<br />\n"; $error .= "The limit is 2MB (2048KB).<br />\n"; } else if ($_FILES['picFile']['type'] == "image/jpeg" || $_FILES['picFile']['type'] == "image/pjpeg" || $_FILES['picFile']['type'] == "image/jpg") { $srctemp = imagecreatefromjpeg ($_FILES['picFile']['tmp_name']); $uploaded = true; } else if ($_FILES['picFile']['type'] == "image/gif") { $srctemp = imagecreatefromgif ($_FILES['picFile']['tmp_name']); $uploaded = true; } else if ($_FILES['picFile']['type'] == "image/png") { $srctemp = imagecreatefrompng ($_FILES['picFile']['tmp_name']); $uploaded = true; } else { echo "The file type: '" . $_FILES['picFile']['type'] . "' is not supported.<br />\n"; echo "Please Choose a File that is either .gif, .png or .jpg (jpeg) format.<br />\n"; echo "(Please note: there is an issue with uploading files using internet explorer or firefox.\n"; echo "We are working to resolve these issues. Meanwhile, have you tried a different browser?<br />\n"; echo "<br /><hr noshade /><strong>Debug $_FILES</strong><pre>" . print_r($_FILES,true) . "</pre><hr noshade />\n"; } } if ($uploaded) { $newName = '../lib/files/' . $_SESSION['special'] . '.jpg'; $srcWidth = imagesx ($srctemp); $srcHeight = imagesy ($srctemp); if ($srcWidth < 200 || $srcHeight < 385) { imagejpeg ($srctemp, $newName, 75); imagedestroy ($srctemp); $stored = true; } else { $cropHeight = (int) ($srcHeight * .95); $cropWidth = (int) ($cropHeight * 200 / 385); $srcX = (int) (($srcWidth - $cropWidth) / 2); $srcY = (int) (($srcHeight - $cropHeight) / 2); $dsttemp = imagecreatetruecolor (200, 385); imagecopyresized ($dsttemp, $srctemp, 0, 0, $srcX, $srcY, 200, 385, $cropWidth, $cropHeight); imagejpeg ($dsttemp, $newName, 75); $stored = true; } } if ($stored) { echo "<meta http-equiv = 'Refresh' content = '0;url=index.php' />\n"; echo "</head>\n<body>\n<div>\nUploaded\n</div>\n"; } else { ?> </head> <body> <?php if ($error != "") { echo "<div>\n$error\n</div>\n"; } ?> <form method = 'post' action = 'pic_upload.php' enctype = 'multipart'> <div> Upload your photo.<br /><br /> It needs to be less than 2MB (2048KB) in size. The system will automatically crop your photo to 200 x 385 pixels.<br /><br /> If you aren't in the middle of the picture, or your picture is too high of a resolution, then the results might not be what you want. If this happens, use some basic picture editing software to crop your photo and try again.<br /><br /> Your picture can be in either .gif, .png or .jpg (jpeg) file format.<br /><br /> <label for = 'picFile'> File: </label> <br /> <input type="hidden" name="MAX_FILE_SIZE" value="30000000" /> <input type = 'file' name = 'picFile' id = 'picFile' /> <br /> <input type = 'submit' name = 'submit' value = 'Upload' /> <br /><br /> (Remember: Your facilitators will be able to see this picture.) <br /><br /> </div> </form> <div> <a href = 'index.php'>Return to your Card Page.</a> </div> <?php } } else { ?> <div> <h4>Your session appears to have expired.</h4> <a href = '../login.php'>Login</a><br /> or<br /> <a href = '../index.php'>Return to Home Page</a> </div> <?php } ?> </body> </html>
In ie and firefox, the output looks like:
The file type: '' is not supported. Please Choose a File that is either .gif, .png or .jpg (jpeg) format. (Please note: there is an issue with uploading files using internet explorer or firefox. We are working to resolve these issues. Meanwhile, have you tried a different browser?
-------------------------------------------------------------------------------- Debug Array Array ( )
--------------------------------------------------------------------------------
Upload your photo.
It needs to be less than...
|
|
|
|
Answer : PHP/XHTML file upload not working with ie or firefox
|
|
|
|
What happens if your form type is set to
multipart/form-data
rather than just
multipart?
Like so <form method = 'post' action = 'pic_upload.php' enctype = 'multipart/form-data'>
|
|
|
|
|