thinkphp3.2.2 method for generating multiple thumbnails _php example

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.