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

QQ登录

只需一步,快速开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[thinkphp学习资料] thinkphp 缩略图

[复制链接]
跳转到指定楼层
楼主
发表于 2018-7-27 15:27:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. function imgs_uploads($path_old = null){7 l5 k$ b0 t, a+ r% R. N: L6 @2 B
  2.       
    & e( q2 t3 T5 j& b
  3.         $images_path = './Uploads/image/shop/';0 ~# l5 \+ f; \: D; v1 i4 P
  4.         if (!is_dir($images_path)) {+ Z2 h- f' E$ I" Z6 R
  5.                 mkdir($images_path);& E4 }& N- O+ y8 B1 B
  6.         }          
    + O6 f% {' c5 r1 q: d5 _/ i* O" g
  7.            ) Q# Y9 e4 \, R7 R7 B' a
  8. $ ?9 C0 \4 i+ }: t- L% `9 N. s. T( K
  9.         $upload = new \Think\Upload();//实列化上传类( _" G, a! L  L% E' _: _) g7 i& n
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小; a6 O. r! m* X
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀
    1 G+ k  @' S: n3 I5 q
  12.         $upload->rootPath =$images_path;//上传目录. f3 {. d3 O! p$ V& Y6 H; f& d  t' X
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录; f" w  {& |1 i
  14.         //$upload->autoSub     = true;, `  N3 x7 B7 E5 r  H. ?
  15.         //$upload->subName     = array('date','Ymd');1 r3 g* A6 B) O. H5 B6 U' d- a
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则- O3 i6 L& c* g+ B
  17.                 $upload->replace = false;9 |! G" }8 D9 g
  18.         $info= $upload->upload();//执行上传方法
    $ c0 g# @" U' z  ^
  19.         if(!$info){
    # L6 u0 C: z# W; J0 ^: ?  X
  20.             $res['status'] = 0;
    ) K' N  {1 D4 v5 g  G! N
  21.                         $res['res'] = $upload->getError();$ |8 @7 A% S  c% X' T
  22.                        
    3 C; @0 m5 f' x% `$ g' D
  23.         }else {( ?+ [  q' n$ _% T7 R
  24.             5 u+ T0 p# |6 R2 Y$ ?
  25.             //获取上传文件信息; b% |8 C  d" j6 ?( L( L: B
  26.             foreach ($info as $file){  P5 s0 i, l- g
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];3 f* s1 v, q% m, k% s! L- a& n
  28.                         $name[]=$file['key'];
    + I. Y. R, q+ ?: J2 }# F9 i
  29.   q' G) {' X- @' e4 V" f9 Z
  30.                 - ~. P1 [& {) W/ q$ z
  31.             }
    4 \6 w, d$ s1 U) y% S" S
  32.             //图片物理目录删除、改名图片用7 N7 s# }' J; u7 ]* D
  33.                         $bigimg=$file['savepath'].$file['savename'];* n, B% b4 |. g. o) ^& U& v' c$ I
  34.                         //$_POST['goods_big_img']=$bigimg;$ G1 S3 u, i) ~1 w3 t( [6 }3 l
  35.                         ' @7 }. O. k. {$ H" s4 L
  36.                         * |- u  y; i( r" @7 y  h3 F( f
  37.                         $image=new \Think\Image();
    ! q, h" q& k0 u& c# y& E
  38.                         4 |0 E0 ]! w5 h; l; |
  39.                         $srcimg=$upload->rootPath.$bigimg;
    5 b6 c* \: P7 J6 G' _+ j  e# k
  40.                         $image->open($srcimg);
    2 J9 n5 b: i- G4 P
  41.                         $image->thumb(500,500);
    & |' y9 _5 A2 N/ ^$ Y
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];$ ~! n$ J. h: e0 v  d. D. v9 {3 p
  43.                         $image->save($upload->rootPath.$smallimg);
    ( u+ z# Y# s; u1 s
  44.                         //$_POST['goods_small_img']=$smallimg;: @, i6 Q# F8 h7 ~
  45.            
    0 w, x: ]; Y8 [/ x% g6 M

  46. 3 z8 z" g+ L3 o1 N, B& y/ r: O
  47.                 , Q& ?0 E3 B6 P1 Q# }# |
  48.                         if ($path_old && $img_path) {
    3 ^+ p, c/ Z4 D/ L4 s; K! |
  49.                                 unlink('.' . $path_old);& I' j5 Y5 W5 M4 ]. ^
  50.                         }, K- E* J/ A+ \
  51.                 7 N; ?4 |; N8 D
  52.                
    " p' a! i. q, }' M* r' S0 u# \
  53.                         $res['stats'] = 1;
    6 n8 l) x# K2 i$ x6 f
  54.                         $res['res'] = $smallimg;
    1 h/ V+ ?0 u  U: b0 ^" j4 p( l
  55.                         $res['name']=$name;
    0 m: a2 {* o: u8 m/ Y3 \3 O- N
  56.         }$ o7 a5 g% p$ N2 k
  57.         
    ; f  l% ]. k- P* S/ g# `
  58.           |- v# G* b' Y- B8 g8 P
  59. }
复制代码

) C4 D5 J7 ?* S/ m; o* b% I$ E3 R/ M( X! K
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 支持支持 反对反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

GMT+8, 2026-6-20 02:59 , Processed in 0.070333 second(s), 20 queries .

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