Home > Backend Development > PHP Tutorial > Solution to the problem that ThinkPHP3.0 thumbnails cannot be saved to subdirectories_PHP tutorial

Solution to the problem that ThinkPHP3.0 thumbnails cannot be saved to subdirectories_PHP tutorial

WBOY
Release: 2016-07-21 15:15:35
Original
819 people have browsed it

Solution 1 (the official method provided by ThinkPHP, I have not tested it): Upgrade to the latest UploadFile.class.php of ThinkPHP3.1 (https://github.com/ liu21st/extend/tree/master/Extend/Library/ORG/Net), download and replace the original UploadFile.class.php

Solution 2: Modify UploadFile.class.php Part of the code

This is my own solution, add a thumbnail subdirectory generation function
Step 1>>

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

Copy the code The code is as follows:

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

Change line 158 in UploadFile.class.php to
Copy code The code is as follows:

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

Finally the problem is solved!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326109.htmlTechArticleSolution 1 (the official method provided by ThinkPHP, I have not tested it): Upgrade to the latest ThinkPHP3.1 UploadFile.class.php (https://github.com/liu21st/extend/tree/master/Exte...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template