Home  >  Article  >  Backend Development  >  thinkphp3.2.2 realizes the method of generating multiple thumbnails, thinkphp3.2.2 multiple_PHP tutorial

thinkphp3.2.2 realizes the method of generating multiple thumbnails, thinkphp3.2.2 multiple_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:151093browse

thinkphp3.2.2 realizes the method of generating multiple thumbnails, thinkphp3.2.2 has multiple thumbnails

The example in this article describes the method of generating multiple thumbnails in thinkphp3.2.2. Share it with everyone for your reference.

The specific implementation method is as follows:

Copy code The code is as follows:
public function dz_upload() { //Upload multiple thumbnails Upload 2 thumbnails
If (isset($_FILES['ori_img'])){
$upload = new ThinkUploadFile(); // Instantiate upload class
$upload->maxSize = 3000000;//Set the attachment upload size C('UPLOAD_SIZE');
//$upload->savePath = './Public/Uploads/' . $path; //Set the attachment upload directory
$upload->savePath = './Public/Uploads/' . 'thumb/'; // Set the attachment upload directory
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // Set attachment upload type
$upload->saveRule = 'time';
$upload->uploadReplace = true; //Whether the file with the same name exists or whether to overwrite
$upload->thumb = true; //Whether to thumbnail the uploaded file
$upload->thumbMaxWidth = '100,300'; //Thumbnail processing width
$upload->thumbMaxHeight = '50,150'; //Thumbnail processing height
//$upload->thumbPrefix = $prefix; //Thumbnail prefix
$upload->thumbPrefix = 'm_,s_'; //Produce 2 thumbnails
//$upload->thumbPath = './Public/Uploads/' . $path . date('Ymd', time()) . '/'; //Thumbnail saving path
$upload->thumbPath = './Public/Uploads/' . 'thumb/' . date('Ymd', time()) . '/'; // Thumbnail saving path
 
//$upload->thumbRemoveOrigin = true; //Delete the original image after uploading it
$upload->thumbRemoveOrigin = false; //Delete the original image after uploading it
$upload->autoSub = true; //Whether to use subdirectories to save images
$upload->subType = 'date'; //Subdirectory saving rules
$upload->dateFormat = 'Ymd'; //The time format when the subdirectory saving rule is date

if (!$upload->upload()) {//Upload error message
echo json_encode(array('msg' => $this->error($upload->getErrorMsg()), 'status' => 0));
} else {// Upload successful Get uploaded file information
$info = $upload->getUploadFileInfo();
$picname = $info[0]['savename'];

         $picname = explode('/', $picname);                                     //$picname = $picname[0] . '/' . $prefix . $picname[1];
$picname = $picname[0] . '/' . '_hz' . $picname[1];
                    print_r($picname);                        echo json_encode(array('status' => 1, 'msg' => $picname));
}  
}
}

Calling method:



Copy code The code is as follows:$k=A("Index"); // Call the koo method of the controller Index Key points (lish)
$slt=$k->dz_upload();

It should be noted here that thinkphp3.2.2 does not have the UploadFile and UploadImage classes. You need to extract them from the extension package and add them yourself, and put them in the ThinkPHPLibraryThink directory.

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

http://www.bkjia.com/PHPjc/930189.html

truehttp: //www.bkjia.com/PHPjc/930189.htmlTechArticlethinkphp3.2.2 realizes the method of generating multiple thumbnails, thinkphp3.2.2 multiple thumbnails This article describes thinkphp3.2.2 Implement a method to generate multiple thumbnails. Share it with everyone for your reference. Tool...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn