ThinkPHP3.0 thumbnails cannot be saved to a subdirectory workaround summary _php Tutorial

Source: Internet
Author: User
THINKPHP3.0 after uploading a file thumbnails can not be saved to subdirectories, because UploadFile.class.php this upload class Getsubname () function can only create subdirectories of the original image and not create a thumbnail of the sub-directory, can be said to be a bug.

Solution One (thinkphp officially provided, I have not tested): Upgrade to ThinkPHP3.1 the latest UploadFile.class.php (https://github.com/liu21st/extend/tree/ master/extend/library/org/net), replace the original UploadFile.class.php after downloading

Workaround two: Modify part of the code for UploadFile.class.php

This is your own solution, add a thumbnail of the sub-directory generation function

Step 1>>

Create a Getthumbsubname () function in UploadFile.class.php by imitating the getsubname () function

copy code

Private function Getthumbsubname ($file) {
Switch ($this->subtype) {
case ' date ':
$dir = Date ($this->dateformat,time ());
break;      
Case ' hash ':
Default:
$name = MD5 ($this->thumbpath);
$dir = ";
for ($i =0; $i < $this->hashlevel; $i + +) {
$dir. = $name {$i}. ' /';  
}
Break;

if (!is_dir ($this->thumbpath). $dir) {
mkdir ($this->thumbpath). $dir);
}
return $dir;
}

Step 2>>

UploadFile.class.php in line 158 instead

The code is as follows Copy Code

$thumbPath = $this->thumbpath? $this->thumbpath. ($this->autosub? $this->getthumbsubname ($file). ' /': '): $file [' Savepath '];

http://www.bkjia.com/PHPjc/632175.html www.bkjia.com true http://www.bkjia.com/PHPjc/632175.html techarticle THINKPHP3.0 After uploading a file thumbnails can not be saved to subdirectories, because UploadFile.class.php this upload class Getsubname () function can only create subdirectories of the original image and not create a thumbnail ...

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