Customer upload the image size is not standard, want to let the picture unified into 150x113 size. From the Internet to search the program in IE with normal, to the other browser (such as Sogou browser, etc.) is not, what is the reason? (feeling is always not executed)
The code is as follows:
Session_Start ();
if (Isset ($_session[' AdminName ')) && isset ($_session[' AdminPass ']) {
//****************************************
Generate Thumbnails ========================================
$myname =date ("Ymdhis");
$filename = "product/min/". $myname; Small picture file name
$resizewidth = 150; Create the width of the picture
$resizeheight = 113; Height of the resulting picture
function Resizeimage ($im, $maxwidth, $maxheight, $name) {
$resizewidth = $resizeheight = false;
$width = Imagesx ($im);
$height = Imagesy ($im);
if ($maxwidth && $width > $maxwidth) | | ($maxheight && $height > $maxheight)) {
if ($maxwidth && $width > $maxwidth) {
$widthratio = $maxwidth/$width;
$resizewidth =true;
}
if ($maxheight && $height > $maxheight) {
$heightratio = $maxheight/$height;
$resizeheight =true;
}
if ($resizewidth && $resizeheight) {
if ($widthratio < $heightratio) {
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif ($resizewidth) {
$ratio = $widthratio;
}elseif ($resizeheight) {
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if (function_exists ("imagecopyresampled")) {
$newim = Imagecreatetruecolor ($newwidth, $newheight);
Imagecopyresampled ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = Imagecreate ($newwidth, $newheight);
Imagecopyresized ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
Imagejpeg ($newim, $name. ". jpg");
Imagedestroy ($newim);
}else{
Imagejpeg ($im, $name. ". jpg");
}
}
if (isset ($_files[' image ' [' size '])) {
if ($_files[' image ' [' type '] = = "Image/pjpeg") {
$im = imagecreatefromjpeg ($_files[' image ' [' tmp_name ']);
}elseif ($_files[' image ' [' type '] = = "Image/x-png") {
$im = imagecreatefrompng ($_files[' image ' [' tmp_name ']);
}elseif ($_files[' image ' [' type '] = = "Image/gif") {
$im = imagecreatefromgif ($_files[' image ' [' tmp_name ']);
}
if ($im) {
if (File_exists ("$filename. jpg")) {
Unlink ("$filename. jpg");
}
Resizeimage ($im, $resizewidth, $resizeheight, $filename); Generate a small image
Imagedestroy ($im);
echo "Upload successful, image filename is:";
echo $myname. " JPG ";
}
}
//****************************************
}else{
echo "";
}
?>
Reply to discussion (solution)
You see if there's a generated picture in the product/min/directory.
ie, firefox,chrome try, these three lines say the code is not a problem.