Thinkphp3.2.2 method for generating multiple thumbnails _ php instance

Source: Internet
Author: User
This article describes how to generate multiple thumbnails using thinkphp3.2.2. It is of great practical value to call the UploadFile class of the ThinkPHP extension package to process the thumbnails of uploaded images, for more information about how to generate multiple thumbnails, see the example in this article. Share it with you for your reference.

The specific implementation method is as follows:

The Code is as follows:

Public function dz_upload () {// upload multiple thumbnails and upload two thumbnails
If (isset ($ _ FILES ['ori _ img ']) {
$ Upload = new \ Think \ UploadFile (); // instantiate the upload class
$ Upload-> maxSize = 3000000; // sets 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 '); // you can specify the attachment upload type.
$ Upload-> saveRule = 'time ';
$ Upload-> uploadReplace = true; // whether a file with the same name is overwritten
$ Upload-> thumb = true; // whether to perform thumbnail processing on the uploaded file
$ Upload-> thumbMaxWidth = '000000'; // The width of the thumbnail processing.
$ Upload-> thumbMaxHeight = '000000'; // The height of thumbnails.
// $ Upload-> thumbPrefix = $ prefix; // the prefix of the thumbnail.
$ Upload-> thumbPrefix ='m _, s _ '; // produce two thumbnails.
// $ Upload-> thumbPath = './Public/Uploads/'. $ path. date ('ymmd', time (). '/'; // Save the thumbnail path
$ Upload-> thumbPath = './Public/Uploads/'. 'thumb/'. date ('ymmd', time ().'/'; // Save the thumbnail path

// $ Upload-> thumbRemoveOrigin = true; // Delete the original image after uploading the image
$ Upload-> thumbRemoveOrigin = false; // Delete the original image after uploading the image
$ Upload-> autoSub = true; // whether to use a subdirectory to save an image
$ Upload-> subType = 'date'; // sub-directory save rule
$ Upload-> dateFormat = 'ymd'; // The time format when the sub-directory storage rule is date

If (! $ Upload-> upload () {// upload error message
Echo json_encode (array ('msg '=> $ this-> error ($ upload-> getErrorMsg (), 'status' => 0 ));
} Else {// the uploaded file is successfully obtained.
$ 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 ));
}
}
}


Call method:

The Code is as follows:

$ K = A ("Index"); // call the koo method of the controller Index (lish)

$ Slt = $ k-> dz_upload ();

Note that thinkphp3.2.2 does not have UploadFile. The UploadImage class needs to be extracted from the extension package and added to it by yourself. Put them in the ThinkPHP \ Library \ Think directory.

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.