PHP GD Library
PHP uses the GD library to generate thumbnails.
Code:
-
- Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK");
- Ini_set ("Date.timezone","Asia/chong");
- //Determine if the file is empty
- if (empty($_files)) {
- Echo "Upload file too large" ;
- Exit ;
- }
- //Determine if there is an error in file upload
- if ($_files[' pic '] [' ERROR ']) {
- Echo "Upload file";
- Exit ;
- }
- //Determine if file type is illegally getting 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 uploading of files";
- Exit ;
- }
- $file = Date (' ymdhis '). Rand (). "." . $ex ;
- $src = $_files [' pic '] [' Tmp_name '];
- $des = "upload/" . $file ;
- $rs =move_uploaded_file ($src,$des);
- //thumbnail image
- //Read already uploaded pictures
- $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 blank new picture
- $newimage =imagecreatetruecolor ($width, $height);
- //copy Source Picture content copy new picture
- Imagecopyresized ($newimage, $image, 0,0, 0,0 , $width, $height, $w, $h);
- $filename = "Upload/s_" . $file ;
- Imagejpeg ($newimage,$filename);
http://www.bkjia.com/PHPjc/714728.html www.bkjia.com true http://www.bkjia.com/PHPjc/714728.html techarticle PHP GD library PHP uses the GD library to generate thumbnails. Code: formmethod= "POST" action= "suo_do.php" enctype= "Multipart/form-data" inputtype= "file" name= "pic"/inputtype= "Sub MIT "Value= ...