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

QQ登录

只需一步,快速开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[thinkphp学习资料] thinkphp 缩略图

[复制链接]
跳转到指定楼层
楼主
发表于 2018-7-27 15:27:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. function imgs_uploads($path_old = null){
    . F& n/ G% }5 {# _9 ?, Y
  2.       
    % U4 R; _8 D, q, K! q& ^$ z' V
  3.         $images_path = './Uploads/image/shop/';# i. h) }7 W. J5 _) N, i
  4.         if (!is_dir($images_path)) {+ ~& e) R! n0 J- A7 {6 C$ s* G
  5.                 mkdir($images_path);2 l! I, L- u- Q  [7 Z
  6.         }          
    - j4 u9 u+ N, N. A
  7.           
    5 j6 P9 M% A8 j/ g! S5 D  ^$ _

  8. ; G1 ^: y8 p6 ~  {8 {5 \
  9.         $upload = new \Think\Upload();//实列化上传类
    % y0 K5 {: e) u
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小
    ) @* [: t- [( [$ c5 J
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀8 d0 x1 b% [/ [% x
  12.         $upload->rootPath =$images_path;//上传目录
    ' f7 O1 R" d; B- e1 w
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录8 _2 f3 B* y9 M) C% s0 w3 q
  14.         //$upload->autoSub     = true;
    - H' @7 |+ w* b2 f" V
  15.         //$upload->subName     = array('date','Ymd');2 c: F* ~" }" P/ k6 ]# \
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则- S, I1 |* L8 P) r# l
  17.                 $upload->replace = false;
    ) f0 P3 H" _" Y  {4 k- A0 N" a
  18.         $info= $upload->upload();//执行上传方法6 {* W# b7 S, I# c7 D
  19.         if(!$info){# _; H: F! n. U1 s
  20.             $res['status'] = 0;0 H" K+ n1 M/ r
  21.                         $res['res'] = $upload->getError();
    4 `3 h  e: i! J6 I+ Y2 m
  22.                        
    ; H2 ?- X0 H" q- [5 P( e( `
  23.         }else {
    8 J, ?$ o) b" Z! f2 C
  24.             
    5 @" i5 H: _. U/ N5 O0 c
  25.             //获取上传文件信息
    + X8 p! V: U( l  O0 ?+ ]* ^% }
  26.             foreach ($info as $file){8 V4 o" a3 c0 P0 ]) D
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];  z. e/ C# b# n
  28.                         $name[]=$file['key'];- o9 q% E7 }1 f$ W! j

  29. + R  p) P, H) |* F5 u: b/ D
  30.                
    5 p5 m; M/ |; e. \8 _5 |
  31.             }( n/ H; Z4 b# C/ w6 o. M
  32.             //图片物理目录删除、改名图片用
    ! I4 Z; L/ P5 E& q0 V
  33.                         $bigimg=$file['savepath'].$file['savename'];
    5 n! k: M0 A- }, D
  34.                         //$_POST['goods_big_img']=$bigimg;
    ! T9 }' Z" W$ G
  35.                        
    ' b$ h: b+ F! j/ [$ I
  36.                        
    ! y- @/ r7 Y& R; T3 q3 E0 y' W
  37.                         $image=new \Think\Image();
    5 }& }2 Y7 r* b0 D* k
  38.                         7 @9 @+ f' D6 |8 i# D  Y* Z7 O% `- ]
  39.                         $srcimg=$upload->rootPath.$bigimg;% g8 p3 H0 M* J% c  c
  40.                         $image->open($srcimg);; G, z7 y5 W* x; W
  41.                         $image->thumb(500,500);
    9 ^! L& Q( q2 w' |# c) n6 i2 X% Q
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];
    + d, J; v- W9 i
  43.                         $image->save($upload->rootPath.$smallimg);
    + |: L) J+ s, R* m0 b
  44.                         //$_POST['goods_small_img']=$smallimg;
    9 Y5 a5 ]: S3 j- O* L6 e) p
  45.            
    9 O5 E( [8 ]$ g9 o- G

  46. 9 {8 M2 [5 G. m% r5 W. Y% z* h3 [
  47.                 2 T0 H( H! i+ A( m3 Y
  48.                         if ($path_old && $img_path) {
    4 s! F3 Y9 ]  |9 ]0 H: r
  49.                                 unlink('.' . $path_old);5 {* C$ b: |9 k  L* `
  50.                         }- i" @3 Q  q; G+ W/ i
  51.                
    ( m; q: K7 m) {2 W+ G5 U
  52.                
    # ^: S) H6 J$ @5 m% E
  53.                         $res['stats'] = 1;
    4 q5 a+ M. J5 F7 S6 r
  54.                         $res['res'] = $smallimg;8 z4 ^9 S" p6 \" }! U0 o& r" e
  55.                         $res['name']=$name;5 s* R1 l/ p9 Q  U9 g! a
  56.         }/ C3 t3 X( y* `; M' f6 K6 q
  57.         ! _, y" c, R- S5 Q$ V$ g5 y/ M
  58.        
    : F! G; p0 H: }- f6 u
  59. }
复制代码
7 V' K! w( R) }# L
5 d5 L( _% `" A: I9 r; B
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 支持支持 反对反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

GMT+8, 2026-3-16 23:43 , Processed in 0.055194 second(s), 21 queries .

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