一、先看我的上传程序吧。
PHP Code复制内容到剪贴板
- import('ORG.Net.UploadFile');
- $upload = new UploadFile();
- $upload->thumb = true;
- $upload->thumbMaxWidth = '100,200';
- $upload->thumbMaxHeight = '100,250';
- $upload->thumbPrefix = '';
- $upload->thumbSuffix = '_t100,_t200';
- $upload->thumbPath = '';
- $upload->autoSub = true;
- $upload->subType = 'date';
- $upload->dateFormat = 'Y/d/';
- $upload->saveRule = time() + rand(1000,9999);
- $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
- $upload->savePath = THINK_PATH . '..//puploads/';
- if(!$upload->upload()) {
- echo $upload->getErrorMsg();
- } else {
- $info = $upload->getUploadFileInfo();
- }
二、修改ThinkPHP\Lib\ORG\Net\UploadFile.class.php的,大概151行左右
PHP Code复制内容到剪贴板
- $image = getimagesize($filename);
- //yxy add
- $file_savename = $file['savename'];
- $sub_path = ”;
- if($this->autoSub){
- $sub_path = $this->getSubName($file).‘/’;
- $file_savename = str_replace($sub_path,”,$file_savename);
- }
- if(false !== $image) {
- //是图像文件生成缩略图
- $thumbWidth = explode(',',$this->thumbMaxWidth);
- $thumbHeight = explode(',',$this->thumbMaxHeight);
- $thumbPrefix = explode(',',$this->thumbPrefix);
- $thumbSuffix = explode(',',$this->thumbSuffix);
- $thumbFile = explode(',',$this->thumbFile);
- $thumbPath = $this->thumbPath?$this->thumbPath:$file['savepath'];
- //yxy add
- $thumbPath = $thumbPath . $sub_path;
- // 生成图像缩略图
- import($this->imageClassPath);
- $realFilename = $this->autoSub?basename($file['savename']):$file['savename'];
- for($i=0,$len=count($thumbWidth); $i<$len; $i++) {
- $thumbname = $thumbPath.$thumbPrefix[$i].substr($realFilename,0,strrpos($realFilename, '.')).$thumbSuffix[$i].'.'.$file['extension'];
- Image::thumb($filename,$thumbname,'',$thumbWidth[$i],$thumbHeight[$i],true);
- }
- if($this->thumbRemoveOrigin) {
- // 生成缩略图之后删除原图
- unlink($filename);
- }
其中的yxy add 就是我们需要手动增加的。有二处哦。这样一修改后,Thinkphp的缩略图上传所在的目录就跟我们上传的图片在同一个目录层级下的了。
当然,如果你还想更加自由的修改,参与以上就可以修改达到你想的目的了!
版权声明:若无特殊注明,本文皆为( yueshuo )原创,转载请保留文章出处。