cncml手绘网

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

作者: admin    时间: 2018-7-27 15:27
标题: thinkphp 缩略图
  1. function imgs_uploads($path_old = null){4 c& ?. w+ v& H. g& y7 i9 T) q
  2.       
    & Q4 T9 K, Q( n0 l% t  q2 ?
  3.         $images_path = './Uploads/image/shop/';8 y) x3 S. i. Q( E9 y
  4.         if (!is_dir($images_path)) {3 ^6 o, k: Z; X: y! y+ o
  5.                 mkdir($images_path);
    2 x7 v: k9 d7 P. T: q
  6.         }          
    8 U) Y; w" o, h5 s/ a
  7.            & a  `. O6 R6 h9 U. Y
  8. / h+ f  g& h6 {9 A! X
  9.         $upload = new \Think\Upload();//实列化上传类* c0 c" f$ J! F  `3 A
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小* S0 ?5 }7 {2 K% d% K. B+ G9 E
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀
    - }& k' p! w1 _* Y
  12.         $upload->rootPath =$images_path;//上传目录) u' ]1 d2 [5 v4 @
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录+ c: X' V7 p$ Z: f8 l$ m4 x
  14.         //$upload->autoSub     = true;! I9 |6 J  q. ]8 W) `
  15.         //$upload->subName     = array('date','Ymd');
    + {, r; c( m9 X
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则
    9 T0 q. P% _+ m+ R% |8 Q7 e0 T
  17.                 $upload->replace = false;* L- M: b# ?0 K
  18.         $info= $upload->upload();//执行上传方法
    7 b/ ]9 v' `2 h9 C) E
  19.         if(!$info){9 S; i/ u; P/ I( y, V& H
  20.             $res['status'] = 0;& r  |6 I5 D" u) s  \. |# X
  21.                         $res['res'] = $upload->getError();
    # T3 M/ A1 P, X7 k: D* U
  22.                         * e3 ^/ _" R- Y8 \' A) D
  23.         }else {. Z( Z; H: z4 c5 t6 N" B
  24.             
    0 `, Z, }% L+ n: F& @( B1 @$ l
  25.             //获取上传文件信息  k. @, {' s& j
  26.             foreach ($info as $file){' P: N$ v9 ?6 y; f: p% r" _6 ]
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
    9 ^! ~/ Z4 Y1 J& W
  28.                         $name[]=$file['key'];( v1 L; L4 D# ^! [
  29. 2 {' J! Y4 w7 a  }
  30.                
    ) B" ^; Y8 y3 }3 q3 V
  31.             }
    # j: A- l2 b" V$ f9 z; g
  32.             //图片物理目录删除、改名图片用7 L4 k& U% e9 \2 A6 J$ q5 Z
  33.                         $bigimg=$file['savepath'].$file['savename'];9 {2 q% r5 D- G+ ^" a
  34.                         //$_POST['goods_big_img']=$bigimg;) }$ g. S' E) P. E: Z
  35.                         2 M4 ]" z6 |  I' ^$ B
  36.                         7 n: r# n: E- p- L- i
  37.                         $image=new \Think\Image();) y+ B$ \' E7 q. \. G; w
  38.                        
    8 e: C6 {( D6 P7 b' H2 B  I
  39.                         $srcimg=$upload->rootPath.$bigimg;" r1 l8 e; ~1 g6 Z" i* G
  40.                         $image->open($srcimg);
    ' y3 \( M/ L( L+ o
  41.                         $image->thumb(500,500);
      l# d3 v; C: G- C* M+ X" B
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];. O% |& W1 f$ Y1 G1 t( q# t" u
  43.                         $image->save($upload->rootPath.$smallimg);4 P  W: J' [! A' Q' W" w; G$ T
  44.                         //$_POST['goods_small_img']=$smallimg;, U! `5 m, J' k* r
  45.            
    . k% c7 T. `4 I
  46. ' `( O. q: s4 k5 S
  47.                
    ; A; w. {' K6 A9 a5 ^4 T
  48.                         if ($path_old && $img_path) {/ B5 c* K4 H8 P' ~% w# x
  49.                                 unlink('.' . $path_old);
    # i2 \' W8 F4 `, T3 N  R7 W5 C/ c
  50.                         }( w8 u! U' r+ b5 @+ h  F( ~
  51.                
    ! L0 l" k# s, z6 [, c% E* l
  52.                
    / h* w. m% w; X2 D( w  c# i
  53.                         $res['stats'] = 1;: U8 ^/ j1 {3 a+ _( w
  54.                         $res['res'] = $smallimg;* A( ~, C3 Q' \3 @! G
  55.                         $res['name']=$name;
    ; [" E6 I& W1 C) n) {# [# D
  56.         }8 G, P: w( s0 t' \  h" G
  57.         
    1 B$ h& A' T5 z, D- I
  58.        
    ' i5 Y" `& j3 |: L
  59. }
复制代码
' Z; t2 I% o2 G1 M6 w. d7 m
& X+ s" L0 n- j





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