The example in this article describes the method of generating multiple thumbnails in thinkphp3.2.2. Share it with everyone for your reference.
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:
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.