ThinkPHP3.0 thumbnail cannot be saved to sub-directory solution summary

Source: Internet
Author: User
Tags extend php code

Solution 1 (I have not tested ThinkPHP's official solution): upgrade ThinkPHP3.1 to the latest UploadFile. class. php (, download and replace the original UploadFile. class. php

Solution 2: modify part of UploadFile. class. php code

This is a solution by myself. Add a sub-directory of the thumbnail to generate a function.

Step 1>

UploadFile. class. php imitates the getSubName () function to create a getThumbSubName () function.

The code is as follows: Copy code

Private function getThumbSubName ($ file ){
Switch ($ this-> subType ){
Case 'date ':
$ Dir = date ($ this-> dateFormat, time ());
Case 'hash ':
$ Name = md5 ($ this-> thumbPath );
$ Dir = '';
For ($ I = 0; $ I <$ this-> hashLevel; $ I ++ ){
$ Dir. = $ name {$ I }.'/';
If (! Is_dir ($ this-> thumbPath). $ dir )){
Mkdir ($ this-> thumbPath). $ dir );
Return $ dir;

Step 2>

In UploadFile. class. php, change row 158

The code is as follows: Copy code

$ ThumbPath = $ this-> thumbPath? $ This-> thumbPath. ($ this-> autoSub? $ This-> getThumbSubName ($ file). '/': ''): $ file ['savepath'];

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: 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.