Image Help Please
Posted: Sun Dec 09, 2007 11:39 pm
Ladies and gentlemen,
I read a tutorial from here I believe about uploading images. It works fine in Firefox, but not in IE. I think the problem has to do with the way it saves it. IE cannot save it to the folder (even though I set the folder properties to accessible) but Firefox can. Something with the "\" probably, but I've tried every single possibility. Could someone please look at this below?
The filename is a random hash. The original is replaced by the thumbnail.
I read a tutorial from here I believe about uploading images. It works fine in Firefox, but not in IE. I think the problem has to do with the way it saves it. IE cannot save it to the folder (even though I set the folder properties to accessible) but Firefox can. Something with the "\" probably, but I've tried every single possibility. Could someone please look at this below?
The filename is a random hash. The original is replaced by the thumbnail.
Code: Select all
$rand=randomHash();
// Get the details of "imagefile"
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];
//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);
//Save a copy of the original
imagejpeg($i,"images/$rand.jpg",80);
//Specify the size of the thumbnail
$dest_x = 400;
$dest_y = 400;
//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));
//Save the thumbnail
imagejpeg($thumb, "images/$rand.jpg", 80);