Sample code sharing for generating thumbnails in php (implemented using the gd Library ). The copy code is as follows: the formmethodpostactionsuo_do.phpenctypemultipartform-datainputtypefilenamepicinputtypesubmitvalue uploads 1 form? Phphead
The code is as follows:
Header ("content-type: text/html; charset = gbk ");
Ini_set ("date. timezone", "Asia/chong ");
// Determine whether the file is empty
If (empty ($ _ FILES )){
Echo "uploading files too large ";
Exit;
}
// Determine whether the file is uploaded incorrectly
If ($ _ FILES ['Pic '] ['error']) {
Echo "upload files ";
Exit;
}
// Determine whether the file type is illegal to obtain the file suffix
$ Allowtype = array ("jpg", "png", "jpeg", "gif ");
$ A = explode ('.', $ _ FILES ['Pic '] ['name']);
$ Index = count ($ a)-1;
$ Ex = strtolower ($ a [$ index]);
If (! In_array ($ ex, $ allowtype )){
Echo "Illegal File upload ";
Exit;
}
$ File = date ('ymdhis '). rand (). ".". $ ex;
$ Src = $ _ FILES ['Pic '] ['tmp _ name'];
$ Des = "upload/". $ file;
$ Rs = move_uploaded_file ($ src, $ des );
// Thumbnail
// Read the uploaded image
$ Image = imagecreatefromjpeg ($ des );
$ A = getimagesize ($ des );
$ W = $ a [0];
$ H = $ a [1];
If ($ w> $ h ){
$ Width = 300;
$ Height = $ width/$ w * $ h;
} Else if ($ w <$ h ){
$ Height = 300;
$ Width = $ height/$ h * $ w;
} Else {
$ Width = 300;
$ Height = 300;
} Www.jbxue.com
// Create a blank image
$ Newimage = imagecreatetruecolor ($ width, $ height );
// Copy source image content copy New Image
Imagecopyresized ($ newimage, $ image, 0, 0, 0, $ width, $ height, $ w, $ h );
$ Filename = "upload/s _". $ file;
Imagejpeg ($ newimage, $ filename );
The http://www.bkjia.com/PHPjc/718620.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/718620.htmlTechArticle code is as follows: form method = "post" action = "suo_do.php" enctype = "multipart/form-data" input type = "file" name = "pic"/input type = "submit" value = ""Upload 1" // form? Php head...