cncml手绘网

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

作者: admin    时间: 2018-7-27 15:27
标题: thinkphp 缩略图
  1. function imgs_uploads($path_old = null){
    * C2 y5 P1 l0 ?2 V! s" V
  2.        ! }8 d1 }9 |9 ^+ N
  3.         $images_path = './Uploads/image/shop/';
      a) Q, v- t! T# I- f& W8 n
  4.         if (!is_dir($images_path)) {& @- {4 @9 R  n+ Y+ p; C
  5.                 mkdir($images_path);
    - v) T3 v' e) j* ?* |  z
  6.         }           ' g; a' H* w9 ?2 u! l3 a7 `9 D
  7.            8 {/ }* }( r0 M  \8 e  y9 t) W9 @% L
  8. 5 F; t0 a5 K" J2 b8 Y
  9.         $upload = new \Think\Upload();//实列化上传类' |: J' B+ x; v% l1 y, ?
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小
    ! l# j, d/ i/ ^
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀, g) c; y! s: p, y. `
  12.         $upload->rootPath =$images_path;//上传目录
    ! R' A& y1 P5 s+ D9 U4 f1 `' }: k
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录
    ! `# ^  ]7 G  l! y
  14.         //$upload->autoSub     = true;9 N+ K# k; v1 O, ^3 D' S: g
  15.         //$upload->subName     = array('date','Ymd');
    & f! I5 g0 z  A" y
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则* M5 m, r5 N8 }9 ]9 ~
  17.                 $upload->replace = false;
    0 S: h5 v$ T. ?$ t& V
  18.         $info= $upload->upload();//执行上传方法' @* F) J' g/ X+ r" v
  19.         if(!$info){0 j+ x& _; S" P1 H* P: l& v+ Z
  20.             $res['status'] = 0;
    # x! C8 f4 w( e. M$ d# b- x1 f
  21.                         $res['res'] = $upload->getError();- e( \5 x3 x- p1 u# _5 d1 H
  22.                        
    # r5 u: g6 Y' Y
  23.         }else {  \+ e! [/ O$ B, ~+ E, H
  24.             
    . j; x8 `; v, S0 Y  A  y% D: _2 W. M
  25.             //获取上传文件信息
    - P  u% v" H4 |5 t0 V( r! F% H
  26.             foreach ($info as $file){
      \" y: B7 r% ]3 E
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
    # T: ^0 U5 b( r, F# C4 x
  28.                         $name[]=$file['key'];1 U9 }. q* C' }6 q: j  R2 }
  29. & l- p7 z* L) l1 }" Y; g5 ?7 W
  30.                 2 h* O/ o; I, l# q* i' h& {
  31.             }
    % W3 e8 ]' c+ ~" a& t
  32.             //图片物理目录删除、改名图片用
    5 b: L$ A; s3 n) n1 T5 M
  33.                         $bigimg=$file['savepath'].$file['savename'];0 Y/ g3 G: X3 F8 _1 Z0 p' ?
  34.                         //$_POST['goods_big_img']=$bigimg;
    5 q+ }, {7 S/ T" f, Z9 t
  35.                        
    + W1 R, r, z* e5 Q  S) D) [3 g5 t
  36.                        
    ' w( J4 k& m$ a4 r0 `( ^
  37.                         $image=new \Think\Image();
    % [! Y+ g. e+ H$ L- \1 ~
  38.                        
    ' g) q, e: H) K/ v! ]
  39.                         $srcimg=$upload->rootPath.$bigimg;) O; I( _% Y5 ^5 u+ Q% u! Y
  40.                         $image->open($srcimg);! R2 h4 f. h+ V- h+ a$ U
  41.                         $image->thumb(500,500);
    , c, e" ~# p, @$ g$ }$ x, e
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];
    8 ^; I8 F: ]$ }3 U( }) a' x
  43.                         $image->save($upload->rootPath.$smallimg);+ B* r1 r" k3 C6 H. y7 o" H
  44.                         //$_POST['goods_small_img']=$smallimg;
    # K$ Y9 ~' e& R) X/ E, x
  45.            ! D2 }0 ^& D9 P* ]

  46. * D1 E$ j1 I6 r4 u5 l7 F
  47.                
    . @$ j: Y/ Z4 Y6 G( s" L3 P) f
  48.                         if ($path_old && $img_path) {
    ; \8 b8 R, D' g) Z5 a8 M0 G; C1 f
  49.                                 unlink('.' . $path_old);
    0 R" p+ B* _7 g* [
  50.                         }
    ' E6 q8 S* K# S0 e( k3 ^1 d
  51.                
    * g$ [' q& ^4 k: J7 ?( \
  52.                
      [+ S4 {" i1 d) S2 k9 X3 ^4 I
  53.                         $res['stats'] = 1;
    7 v4 V) |, m) L3 B
  54.                         $res['res'] = $smallimg;
    1 b9 j0 k; U3 A3 ?: ]% H1 |( j
  55.                         $res['name']=$name;
    $ m5 y: A) V8 Y
  56.         }
    6 A9 k' [% E7 G
  57.         
    4 `  B/ _- U( O- P) f9 u! I1 W1 D
  58.         8 W% e$ i0 N1 _8 D: w. I% d- \
  59. }
复制代码

2 `9 A( Y. V& f: Z* l1 i6 {2 T: F' Y/ o3 _+ V





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