Home > php教程 > php手册 > thinkphp3.2.2实现生成多张缩略图的方法,thinkphp3.2.2多张

thinkphp3.2.2实现生成多张缩略图的方法,thinkphp3.2.2多张

WBOY
Release: 2016-06-13 09:18:29
Original
1089 people have browsed it

thinkphp3.2.2实现生成多张缩略图的方法,thinkphp3.2.2多张

本文实例讲述了thinkphp3.2.2实现生成多张缩略图的方法。分享给大家供大家参考。

具体实现方法如下:

复制代码 代码如下:

public function dz_upload() { //上传多张缩略图   上传2张缩略图 
   if (isset($_FILES['ori_img'])){ 
   $upload = new \Think\UploadFile();// 实例化上传类 
   $upload->maxSize = 3000000 ;// 设置附件上传大小  C('UPLOAD_SIZE');  
   //$upload->savePath = './Public/Uploads/' . $path; // 设置附件上传目录 
   $upload->savePath = './Public/Uploads/' . 'thumb/'; // 设置附件上传目录 
   $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 
   $upload->saveRule = 'time'; 
   $upload->uploadReplace = true; //是否存在同名文件是否覆盖 
   $upload->thumb = true; //是否对上传文件进行缩略图处理 
   $upload->thumbMaxWidth = '100,300'; //缩略图处理宽度 
   $upload->thumbMaxHeight = '50,150'; //缩略图处理高度 
   //$upload->thumbPrefix = $prefix; //缩略图前缀 
   $upload->thumbPrefix = 'm_,s_';  //生产2张缩略图 
   //$upload->thumbPath = './Public/Uploads/' . $path . date('Ymd', time()) . '/'; //缩略图保存路径 
   $upload->thumbPath = './Public/Uploads/' . 'thumb/' . date('Ymd', time()) . '/'; //缩略图保存路径 
   
  //$upload->thumbRemoveOrigin = true; //上传图片后删除原图片 
   $upload->thumbRemoveOrigin = false; //上传图片后删除原图片 
   $upload->autoSub = true; //是否使用子目录保存图片 
   $upload->subType = 'date'; //子目录保存规则 
   $upload->dateFormat = 'Ymd'; //子目录保存规则为date时时间格式 

   if (!$upload->upload()) {// 上传错误提示错误信息 
       echo json_encode(array('msg' => $this->error($upload->getErrorMsg()), 'status' => 0)); 
   } else {// 上传成功 获取上传文件信息 
       $info = $upload->getUploadFileInfo(); 
       $picname = $info[0]['savename']; 
 
       $picname = explode('/', $picname); 
       //$picname = $picname[0] . '/' . $prefix . $picname[1]; 
       $picname = $picname[0] . '/' . '_hz' . $picname[1]; 
       print_r($picname); 
       echo json_encode(array('status' => 1, 'msg' => $picname));
   } 
 } 
}


调用方法:

复制代码 代码如下:

$k=A("Index"); // 调用控制器Index 的koo方法 重点(lish)

$slt=$k->dz_upload();

这里要注意thinkphp3.2.2并没有UploadFile,UploadImage 类,需要从扩展包里提取出来再自己加入,把他们放到ThinkPHP\Library\Think目录下.

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template