Thumbnails generated by php

Source: Internet
Author: User
Tags imagejpeg
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.