cncml手绘网

标题: thinkphp 缩略图 [打印本页]

作者: admin    时间: 2018-7-27 15:27
标题: thinkphp 缩略图
  1. function imgs_uploads($path_old = null){
    - b9 r8 N; _& F, @
  2.        , |0 [# I5 D4 x7 Z9 X6 y
  3.         $images_path = './Uploads/image/shop/';) c  u5 F% m3 G/ ~9 a3 r+ Y* V
  4.         if (!is_dir($images_path)) {2 v; v- _; H  C) S5 }$ _
  5.                 mkdir($images_path);' x9 l9 O) t' p$ z
  6.         }           5 {7 L" B/ h  a5 P1 C# x$ v2 t
  7.           
    6 l: |" e' R/ O
  8. 3 v+ g7 Y8 Q$ E' M4 [" g
  9.         $upload = new \Think\Upload();//实列化上传类
    ) F, y6 ~2 D4 M# R0 J3 w
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小
    2 }# W7 e; A9 w1 ~8 C
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀' p/ `  C! r& K; S
  12.         $upload->rootPath =$images_path;//上传目录
    , v8 Y' F' g4 ^1 _' Z
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录
    2 d% A( H" d" R$ A5 ~6 Q$ p  J
  14.         //$upload->autoSub     = true;
    ) _+ }3 q0 g) U; E: O3 ?
  15.         //$upload->subName     = array('date','Ymd');
    8 Y! l2 X  w; G7 n: v' _
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则0 K  v' ]9 F6 t' P6 Q
  17.                 $upload->replace = false;
    5 i1 M+ H/ ]7 B
  18.         $info= $upload->upload();//执行上传方法* u) [8 _# j* l8 Z& T
  19.         if(!$info){
    , S: C# h, ~& g3 a) r; @
  20.             $res['status'] = 0;% t! v9 C9 C  X
  21.                         $res['res'] = $upload->getError();2 F5 ^& N/ V$ j
  22.                        
    / Z- O5 Q. x  r& ]1 y7 ^: |- ^
  23.         }else {6 G0 H1 u! P' [4 Q* c
  24.             
    ; u! d) y  ~. g+ j" i* _: P$ Q: s+ c
  25.             //获取上传文件信息% E, M2 c9 y! u% c+ n
  26.             foreach ($info as $file){
    $ {1 a8 M6 b1 m" f3 Y
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];& Z, u7 L' [  ]2 z. m
  28.                         $name[]=$file['key'];" ~7 G% g* `: Q4 t- v8 n; Q
  29. ( B9 n+ }4 y4 N. w0 W/ n
  30.                 7 F; e& Y& a+ G1 K( T. {" L
  31.             }
    0 m4 e# q3 x% `4 L: j: A/ J! o
  32.             //图片物理目录删除、改名图片用
    ' V$ o- x+ J: G9 L. x% J. Y
  33.                         $bigimg=$file['savepath'].$file['savename'];
    0 C4 z& u) _+ c$ f$ D( v/ _
  34.                         //$_POST['goods_big_img']=$bigimg;
    8 f; O" g& D4 h+ n6 S+ t
  35.                         % q1 B; s9 a! x8 ~1 R5 l0 B
  36.                        
    4 K, f) y) V2 G/ e, Q
  37.                         $image=new \Think\Image();, U$ F- b0 f; }, {) z8 Y/ K
  38.                         . @0 ^2 s9 T4 ]
  39.                         $srcimg=$upload->rootPath.$bigimg;
    ' L) }% J" U" j! ]: a  z8 C( \
  40.                         $image->open($srcimg);, P0 k5 k1 L# ?
  41.                         $image->thumb(500,500);
    ' a* w" c* }/ W1 o9 x# q& W
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];% r) [- c9 {+ V9 N
  43.                         $image->save($upload->rootPath.$smallimg);
    2 ?3 i) O7 F$ K( t: {. j
  44.                         //$_POST['goods_small_img']=$smallimg;
    / Y8 G! p* Z9 ^  n% D8 u
  45.            
    & v3 q+ Q  t8 l7 ]9 O
  46. ) k* _* f. f; a
  47.                 3 b9 h( Z& c# L3 n% {3 E" R8 D# F
  48.                         if ($path_old && $img_path) {0 K& _/ w( k% I( ]1 l% l; @
  49.                                 unlink('.' . $path_old);  N$ T( H( v. u5 P, |' U
  50.                         }
    9 z3 h0 s0 i# o" x( l
  51.                
    ; i. d) K9 ]6 q
  52.                
    & c. p' i) Z. A" [/ s# p! ^
  53.                         $res['stats'] = 1;, O) m% X/ ^/ ]* S% f
  54.                         $res['res'] = $smallimg;8 G1 J$ i6 z- Y. s8 F- I7 N
  55.                         $res['name']=$name;  J3 d2 W9 C, H2 w
  56.         }
    0 V6 Z# e  f7 c" ?! y% q
  57.         
    8 o2 y: s, p5 |. F# R1 t
  58.         $ ~; Q/ L( S  z# ^/ |0 l
  59. }
复制代码
9 \; d1 `: u; m0 {# e* y

, ~: q; }# m# Z* M- _2 _, I




欢迎光临 cncml手绘网 (http://www.cncml.com/) Powered by Discuz! X3.2