The thumbnails generated by php are not of the standard size for the images uploaded by the customer. The size of the uploaded images is X. The programs found on the Internet are used normally in IE. other browsers (such as Sogou browser) won't work. why? (I feel that I will never execute it)
The code is as follows:
Session_start ();
If (isset ($ _ SESSION ['adminname']) & isset ($ _ SESSION ['adminpass']) {
//************************************** **
// Generate a thumbnail =============================================== ====
$ Myname = date ("YmdHis ");
$ Filename = "product/min/". $ myname; // small image file name
$ Resizewidth = 150; // The width of the generated image
$ Resizeheight = 113; // The height of the generated image
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 ("your filename.jpg ")){
Unlink ("your filename.jpg ");
}
ResizeImage ($ im, $ resizewidth, $ resizeheight, $ filename); // generates a thumbnail.
ImageDestroy ($ im );
Echo "uploaded successfully. The image file name is :";
Echo $ myname. ". jpg ";
}
}
//************************************** **
} Else {
Echo "script window. location = 'login. php' script";
}
?>
Reply to discussion (solution)
Check whether the generated image is in the product/min/directory.
Try ie, Firefox, and chrome. if there are three lines, the code is okay.