您尚未登录,请登录后浏览更多内容! 登录 | 立即注册

QQ登录

只需一步,快速开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 14400|回复: 0
打印 上一主题 下一主题

[thinkphp学习资料] thinkphp 缩略图

[复制链接]
跳转到指定楼层
楼主
发表于 2018-7-27 15:27:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. function imgs_uploads($path_old = null){3 v' |& a0 U2 O; Q6 A/ U6 X7 ?, K
  2.        : }* T# V- z+ y
  3.         $images_path = './Uploads/image/shop/';  C, l/ C( X- m* a1 t3 M; J
  4.         if (!is_dir($images_path)) {1 ]9 r* [8 X  {6 y, ?! M
  5.                 mkdir($images_path);( E( ~, R4 Q: {6 P# K& Q
  6.         }           3 L* E4 ?) L8 X' r1 ^8 C; Y
  7.            0 C* K& c) @0 Z! A; P$ ?7 F! ]
  8. 9 \: S' ]+ T8 W- t! h" z
  9.         $upload = new \Think\Upload();//实列化上传类
    5 C- k5 j& p! E0 o& O
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小
    ' [- l8 K8 m+ v# h
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀
    & J* x) I/ @& u+ E+ k0 m9 G& m" @
  12.         $upload->rootPath =$images_path;//上传目录
    ; ]6 M4 F' I; ^' v  V! @
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录- r# B) _1 q" C0 F5 z7 x, s
  14.         //$upload->autoSub     = true;8 ~5 @1 o- M" A4 }
  15.         //$upload->subName     = array('date','Ymd');% i' T2 k  h8 e0 s" d3 Z2 w
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则# M6 N9 g' [5 a8 n8 \: H! r8 d5 j
  17.                 $upload->replace = false;
    3 `) D* _$ Q( O8 g/ a! Z
  18.         $info= $upload->upload();//执行上传方法0 p) z5 v* _: Q) `
  19.         if(!$info){
    1 O) o  N  X: D( i4 |) Y8 B
  20.             $res['status'] = 0;
    ( i9 Z- z! d% x; F9 ?
  21.                         $res['res'] = $upload->getError();0 N8 O: C0 a, ?6 i- g# c  t
  22.                         ' S( W" |4 O, q( ~) E
  23.         }else {7 k' i6 h  X+ Q# K+ ]% o
  24.             6 ?9 l4 M. P( I( D; ?' z
  25.             //获取上传文件信息/ B! k# j5 e+ u3 w
  26.             foreach ($info as $file){
    0 f* R7 g/ K' R; j, O$ Q0 w$ X
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
    ! J# o) }6 ^# x" P/ X9 I
  28.                         $name[]=$file['key'];: r- ~/ W0 i1 ^) i

  29. 4 N0 O. B* k5 Y* [0 r2 M2 N; Y
  30.                 + R9 s% D3 e. w; Y% I3 i9 i
  31.             }; P& J# ^9 b% r; ]' ^2 X- L. T! n
  32.             //图片物理目录删除、改名图片用% {9 d; s9 c8 ?& s* d
  33.                         $bigimg=$file['savepath'].$file['savename'];
    . I; N5 S5 I: G0 B
  34.                         //$_POST['goods_big_img']=$bigimg;9 V7 T& w. N" ~, t; a6 l5 A! d/ ^5 o) T
  35.                         : ]& d7 g& ^! x% G7 ~
  36.                        
    $ R' G9 A: l/ X' g9 j
  37.                         $image=new \Think\Image();
    ( t, W: v  W1 O4 L# \+ A
  38.                         ) p3 g2 U" L! }5 ]2 s
  39.                         $srcimg=$upload->rootPath.$bigimg;
    5 y, T8 x' o. s
  40.                         $image->open($srcimg);
    % [) k- I$ G9 E. Q8 i
  41.                         $image->thumb(500,500);
    % a' ]2 Y# ]1 ?/ p% i9 Z0 q
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];$ W, e& H) D/ E8 {$ P
  43.                         $image->save($upload->rootPath.$smallimg);1 S( c$ e* T; l% v8 @/ P) W  K! q* v7 U
  44.                         //$_POST['goods_small_img']=$smallimg;8 y+ D7 }# w6 F) N+ q8 o" B
  45.            ; ~) [# V8 Z- N, q/ n; {2 T

  46. ; E4 S8 C7 n, U% L
  47.                 + x0 I: a0 s6 i, k( u" `  |
  48.                         if ($path_old && $img_path) {( S: Z% h% u. ^$ y0 J% o4 |
  49.                                 unlink('.' . $path_old);
    , A1 w( U: ?& z) @- ^
  50.                         }
    ' s  b$ R8 i3 F3 @1 t0 _
  51.                 9 ~" |; V' r2 Q- O* b0 b9 D. A
  52.                
    7 G2 V; a, l( Y# n" M9 a. _
  53.                         $res['stats'] = 1;
    8 f; J# x/ k; }2 R8 S
  54.                         $res['res'] = $smallimg;
    * ^) ]4 I( m" T' E! I2 W% Q6 Z7 D
  55.                         $res['name']=$name;' O7 d3 L9 h2 E1 l+ e' l9 g
  56.         }( N$ o4 E+ |: l' m
  57.         ! a6 w; c) q7 b
  58.        
    7 o6 |8 B3 z' E/ x0 [$ ^, i
  59. }
复制代码

  g* e/ ~! R6 ]) g! s" K# k) K, W" U. @  t4 D# @2 C
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 支持支持 反对反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

GMT+8, 2026-9-21 05:21 , Processed in 0.065790 second(s), 19 queries .

Copyright © 2001-2026 Powered by cncml! X3.2. Theme By cncml!