This script works in FireFox but not in Internet Explorer

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Tue Dec 19, 2006 11:24 pm    Post subject: This script works in FireFox but not in Internet Explorer Reply with quote

Hi all,

this script works fine when I submit the form with FF but when I submit it with IE it instantly returns errors for phpGD, and I have no idea why. I just spent 4 hours getting the script to work so this has really annoyed me. Im guessing its some stupid mistake in the form but I can't spot it.

Quote:
<center><font size="2" face="verdana">
<h2>Forum Image Upload</h2><p>

Use this form to upload an image for use on the forum. Max size 5000KB. BBCode will be provided when the upload completes.<p>

<b>This form doesnt seem to work for IE users, sorry. Im working to fix it ASAP.</b><p>

<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">
Choose a file to upload: <input name="imagefile" type="file">
<input type="submit" value="Upload File">
</form><p>

Allowed file extensions: jpg, jpeg, JPG, JPEG, png, PNG.<p>


<?php

if($_POST){

// Get the details of "imagefile"
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];




$ok = 0;
$allowed_ext = "jpg, jpeg, JPG, JPEG, png, PNG, ";

$extension = pathinfo($filename);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

if($ok == "0") {
echo("<font color=red>This type of file is not allowed to be uploaded.<p>");
}


else{


//Open the image using the imagecreatefrom..() command based on the MIME type.
switch($mimetype) {
case "image/jpg":
case "image/jpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
case "image/png":
$i = imagecreatefrompng($temporary_name);
break;
}

//Delete the uploaded file
unlink($temporary_name);

$rand=date(U);
$savename=$rand.".or.".$filename;

//Save a copy of the original
imagejpeg($i,$savename,75);

//Specify the size of the thumbnail
$dest_x = 500;
$dest_y = 500;

//Is the original bigger than the thumbnail dimensions?
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
//Is the width of the original bigger than the height?
if (imagesx($i) >= imagesy($i)) {
$thumb_x = $dest_x;
$thumb_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$thumb_x = imagesx($i)*($dest_y/imagesy($i));
$thumb_y = $dest_y;
}
} else {
//Using the original dimensions
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}

//Generate a new image at the size of the thumbnail
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);

//Copy the original image data to it using resampling
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));

$savename2=$rand.".th.".$filename;
//Save the thumbnail
imagejpeg($thumb,$savename2, 75);


echo('
<script>
function highlight(field) {
field.focus();
field.select();
}

</script>
<font color=green>The file <b>'.$filename.'</b> has been uploaded.<p>
BBCode: <input type="text" value="[url=http://www.betaarchive.co.uk/imageupload/'.$savename.'][img]http://www.betaarchive.co.uk/imageupload/'.$savename2.'[/img][/url]" readonly size="100" onClick="highlight(this);">

');

}

}

?>



Thanks in advance.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Wed Dec 20, 2006 1:35 am    Post subject: Re: This script works in FireFox but not in Internet Explore Reply with quote

The only thing that I can think of is that the mime type set in IE is different, and when you use the switch statement it is not matching the mime types

Code:
switch( strtolower($mimetype)) {
    case "image/jpg":
    case "image/jpeg":
        $i = imagecreatefromjpeg($temporary_name);
        break;
    case "image/gif":
        $i = imagecreatefromgif($temporary_name);
        break;
    case "image/png":
        $i = imagecreatefrompng($temporary_name);
        break;
    default: //If nothing matches
        print $mimetype; //print out what the var is
}


Does the code above work?
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Dec 20, 2006 9:53 am    Post subject: Reply with quote

Wait a minute, IE handles the Jpeg Mimetype differently. Its pjpeg in IE. DOH! Ill try adding that in and see if it works.

EDIT: Now it works! Such a stupid thing. Trust IE to be different. Thanks for the help roganty, you made me realise what was wrong cutting out that code.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group