加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 学习资料

thinkphp 缩略图

时间:2021-03-21 23:47:14  来源:  作者:
  1. function imgs_uploads($path_old = null){
  2.       
  3.         $images_path = './Uploads/image/shop/';
  4.         if (!is_dir($images_path)) {
  5.                 mkdir($images_path);
  6.         }          
  7.           
  8.  
  9.         $upload = new \Think\Upload();//实列化上传类
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀
  12.         $upload->rootPath =$images_path;//上传目录
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录
  14.         //$upload->autoSub     = true;
  15.         //$upload->subName     = array('date','Ymd');
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则
  17.                 $upload->replace = false;
  18.         $info= $upload->upload();//执行上传方法
  19.         if(!$info){
  20.             $res['status'] = 0;
  21.                         $res['res'] = $upload->getError();
  22.                        
  23.         }else {
  24.             
  25.             //获取上传文件信息
  26.             foreach ($info as $file){
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
  28.                         $name[]=$file['key'];
  29.  
  30.                
  31.             }
  32.             //图片物理目录删除、改名图片用
  33.                         $bigimg=$file['savepath'].$file['savename'];
  34.                         //$_POST['goods_big_img']=$bigimg;
  35.                        
  36.                        
  37.                         $image=new \Think\Image();
  38.                        
  39.                         $srcimg=$upload->rootPath.$bigimg;
  40.                         $image->open($srcimg);
  41.                         $image->thumb(500,500);
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];
  43.                         $image->save($upload->rootPath.$smallimg);
  44.                         //$_POST['goods_small_img']=$smallimg;
  45.            
  46.  
  47.                
  48.                         if ($path_old && $img_path) {
  49.                                 unlink('.' . $path_old);
  50.                         }
  51.                
  52.                
  53.                         $res['stats'] = 1;
  54.                         $res['res'] = $smallimg;
  55.                         $res['name']=$name;
  56.         }
  57.         
  58.        
  59. }
复制代码

 
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
实现php间隔一段时间执行一次某段代码
实现php间隔一段时间
相关文章
    无相关信息
栏目更新
栏目热门