The example of this article describes the method of generating multiple thumbnails by thinkphp3.2.2 implementation. Share to everyone for your reference.
The implementation methods are as follows:
Copy Code code as follows:
Public Function Dz_upload () {//Upload multiple thumbnails upload 2 thumbnail images
if (Isset ($_files[' ori_img ')) {
$upload = new \think\uploadfile ()///materialized upload class
$upload->maxsize = 3000000;//Set attachment upload size C (' upload_size ');
$upload->savepath = './public/uploads/'. $path; Set up attachment upload directory
$upload->savepath = './public/uploads/'. ' thumb/'; Set up attachment upload directory
$upload->allowexts = array (' jpg ', ' gif ', ' PNG ', ' jpeg '); Set Attachment upload Type
$upload->saverule = ' time ';
$upload->uploadreplace = true; Whether a file with the same name is overwritten
$upload->thumb = true; Do you want to do thumbnail processing of uploaded files
$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 thumbnail pictures
$upload->thumbpath = './public/uploads/'. $path. Date (' Ymd ', Time ()). '/'; Thumbnail save path
$upload->thumbpath = './public/uploads/'. ' thumb/'. Date (' Ymd ', Time ()). '/'; Thumbnail save path
$upload->thumbremoveorigin = true; Delete the original picture after uploading the picture
$upload->thumbremoveorigin = false; Delete the original picture after uploading the picture
$upload->autosub = true; Whether to save pictures with subdirectories
$upload->subtype = ' Date '; Sub-directory Save rule
$upload->dateformat = ' YMD '; Child directory Save rule is date time format
if (! $upload->upload ()) {//Upload error message
echo json_encode (' msg ' => $this->error ($upload->geterrormsg ()), ' status ' => 0));
else {//upload successfully 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 (' status ' => 1, ' msg ' => $picname));
}
}
}
Call Method:
Copy Code code as follows:
$k =a ("Index"); Koo method key to call Controller index (Lish)
$slt = $k->dz_upload ();
Notice here that thinkphp3.2.2 does not have a uploadfile,uploadimage class, you need to extract it from the expansion pack and then add them to the Thinkphp\library\think directory.
More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course" and "thinkphp Common methods Summary"
I hope this article will help you with the PHP program design based on thinkphp framework.