cncml手绘网

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

作者: admin    时间: 2018-7-27 15:27
标题: thinkphp 缩略图
  1. function imgs_uploads($path_old = null){
    : E7 o% K# Y7 j; ?; Y
  2.       
    6 m  w0 Z% n! H. W0 W
  3.         $images_path = './Uploads/image/shop/';
    # y# g# Z4 ^4 @
  4.         if (!is_dir($images_path)) {; P& [: L" b. N
  5.                 mkdir($images_path);9 ~2 U* w- v) ~4 w* `/ A0 }7 V6 |$ V
  6.         }          
    + m/ A) j* c- D0 k/ u7 d
  7.            * r* F! L7 ^. ]2 p0 i

  8. . d/ }  Q; G) U# k8 a1 U/ C
  9.         $upload = new \Think\Upload();//实列化上传类
    ' n- m! Z7 R( x5 X* L  ]
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小8 M" H$ K, d) P6 L- @& _1 g% b
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀
    " F- O2 S! `$ y8 I. A& N
  12.         $upload->rootPath =$images_path;//上传目录' a' E7 N8 f) a7 G! ~. e7 K" x2 o* d& @
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录- X, V7 G  S: t4 V1 Z  E: v
  14.         //$upload->autoSub     = true;
    0 w) v4 o( ~# U; t: V
  15.         //$upload->subName     = array('date','Ymd');; U9 z5 X1 U* {; @. K& P
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则
    " S4 C5 t' b: y& j( V" ^
  17.                 $upload->replace = false;
    ) d$ `  m/ q* c4 u9 E' G0 ^
  18.         $info= $upload->upload();//执行上传方法: ?2 C# W  [& s+ u4 ^# o0 R# N  d
  19.         if(!$info){
    + r$ c% J* s/ _* p$ \( C
  20.             $res['status'] = 0;
    $ x3 t, x  j1 U4 w3 A
  21.                         $res['res'] = $upload->getError();
    9 l" g" X! A! N+ D6 o
  22.                         6 ]8 @8 N7 Q- _! S* h5 l( s! I: c
  23.         }else {8 X! w/ }9 |5 s' t  R6 h* X
  24.             
    1 j$ N9 Z; n; I% q" x
  25.             //获取上传文件信息
    - ^$ r0 \  w: Y4 D6 \8 S1 ~8 v7 r; f7 q
  26.             foreach ($info as $file){
    4 P6 {+ P4 _8 A, r  }
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];7 b8 C1 ?0 z$ ^% c* R
  28.                         $name[]=$file['key'];
    $ }8 `4 O( l' p
  29.   l6 y, J0 i" |# c. B
  30.                 8 f* m2 N9 b+ v% e/ Y; M3 c
  31.             }- ^! ?+ i" d- x' D
  32.             //图片物理目录删除、改名图片用4 z6 G5 a9 |1 k) [+ k
  33.                         $bigimg=$file['savepath'].$file['savename'];
    ; S/ X; q8 r5 a
  34.                         //$_POST['goods_big_img']=$bigimg;' d0 h7 P! w" B" X3 n
  35.                         . ?) t9 X( D0 H
  36.                         ! k) F: d+ l- W5 c8 [9 J; @7 J7 A3 ?
  37.                         $image=new \Think\Image();
    + V. `, d% k! j. {* W1 ]; j: L
  38.                           {7 R! ]6 |1 M1 s! ~; m3 S
  39.                         $srcimg=$upload->rootPath.$bigimg;
    2 ]1 C1 b4 W- F$ U4 C9 y7 Q
  40.                         $image->open($srcimg);
    & j& L+ e4 Q! x% K( v
  41.                         $image->thumb(500,500);, X, N8 U4 v% p, ~, ~
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];
    & p0 s; N: L1 R
  43.                         $image->save($upload->rootPath.$smallimg);
    ' P5 }! y, L' l  |3 M0 _; w
  44.                         //$_POST['goods_small_img']=$smallimg;3 w$ N2 Y5 C, [+ b9 c
  45.            ; M0 O# O6 S; ?2 r' `0 \
  46. ! j, L( A; C8 D* i
  47.                
    $ Z" h# |. @4 A+ G! A0 b( E$ I
  48.                         if ($path_old && $img_path) {
    1 n8 K, J; R9 \' O0 f8 ]
  49.                                 unlink('.' . $path_old);; T# z" w% `8 Y9 I* c: H5 R
  50.                         }  k1 I- t  R; M7 O5 Z' l0 O( E
  51.                 ) k  ?! I. p5 m% o" f8 K! d7 h* n
  52.                 4 ~) z7 g& X$ K+ W5 k( ?- {8 p
  53.                         $res['stats'] = 1;
    5 J$ `/ ^3 T- g2 e; Z. x
  54.                         $res['res'] = $smallimg;
    , F9 x1 ]) _9 b$ Z
  55.                         $res['name']=$name;7 k( ?. G( G8 k1 b2 p7 z2 N
  56.         }! l8 G# [' ]! R8 u5 C
  57.         
    % h3 I% F$ G7 ]4 ~% H, M" ~& [
  58.        
    & r& J+ V, C* f/ V* c0 }8 v
  59. }
复制代码
3 y7 f2 n: A' H2 f* @! A( z2 B
/ f/ x% K4 j2 C8 ~





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