教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 ThinkPHP3.0略缩图不能保存到子目录解决办法总结

ThinkPHP3.0略缩图不能保存到子目录解决办法总结

发布时间:2018-12-26   编辑:jiaochengji.com
教程集为您提供ThinkPHP3.0略缩图不能保存到子目录解决办法总结等资源,欢迎您收藏本站,我们将为您提供最新的ThinkPHP3.0略缩图不能保存到子目录解决办法总结资源
THINKPHP3.0上传文件后略缩图不能保存到子目录,是因为UploadFile.class.php这个上传类中getSubName()函数只能创建原图的子目录而不能创建略缩图的子目录,可以说是BUG。

 解决办法一(ThinkPHP官方提供的办法,我并没有测试过):升级到ThinkPHP3.1最新的UploadFile.class.php(https://github.com/liu21st/extend/tree/master/Extend/Library/ORG/Net),下载后替换原来的UploadFile.class.php
 

解决办法二:修改UploadFile.class.php的部分代码

这是自己做的解决办法,增加一个略缩图的子目录生成函数

步骤1>>

UploadFile.class.php中模仿getSubName()函数创建一个getThumbSubName()函数

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9052')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9052>

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

步骤2>>

UploadFile.class.php中158行改为

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1149')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1149>

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

您可能感兴趣的文章:

[关闭]
~ ~