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

QQ登录

只需一步,快速开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[thinkphp学习资料] thinkphp 缩略图

[复制链接]
跳转到指定楼层
楼主
发表于 2018-7-27 15:27:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. function imgs_uploads($path_old = null){) `! c. L- i* V/ K9 n
  2.        % g/ L/ b% x4 I. j# E4 ?- B
  3.         $images_path = './Uploads/image/shop/';" Q3 z* Z7 ?6 c2 H4 k
  4.         if (!is_dir($images_path)) {
    ; K4 E0 x' X- _4 M
  5.                 mkdir($images_path);
    ! B6 f1 j6 L  H' r; G7 S: @
  6.         }          
      x  x1 R% n, e3 L
  7.            - r; G0 ?# q6 k/ Z+ _
  8. 6 p+ g  m, j( }3 F
  9.         $upload = new \Think\Upload();//实列化上传类
    1 ^0 I0 M: M: R3 X
  10.         $upload->maxSize=4145728;//设置上传文件最大,大小
    : B6 B0 E( p( A& y# L; M8 a
  11.         $upload->exts= array('jpg','gif','png','jpeg');//后缀
    + Z( h4 E/ Y9 _) R* T  J1 o8 p! k
  12.         $upload->rootPath =$images_path;//上传目录; W) c6 @: q* c
  13.         $upload->savePath    = ''; // 设置附件上传(子)目录' a0 a. q' m" ]7 b3 F
  14.         //$upload->autoSub     = true;
    + P8 z9 \9 l- Y! T! o
  15.         //$upload->subName     = array('date','Ymd');
    " C% N, A0 V! ?4 f. a, _3 Z
  16.         //$upload->saveName = array('uniqid','');//设置上传文件规则6 c4 g+ d* `! A  i2 S% G) W
  17.                 $upload->replace = false;! l! n( p; w( X5 j
  18.         $info= $upload->upload();//执行上传方法1 f% q3 h; t; `1 K4 F: V/ x, ~3 T
  19.         if(!$info){
    * N9 j3 }4 r) {5 t/ X4 s& b6 [
  20.             $res['status'] = 0;8 r! o' _( D5 _. q& z; i/ l+ d
  21.                         $res['res'] = $upload->getError();3 q$ S6 t5 }0 d0 w+ C0 G6 V  ~
  22.                         " l" G6 U; p" k1 l
  23.         }else {; `1 ]0 X7 f/ L/ ]
  24.             
    1 g4 F' y' F, ?7 }
  25.             //获取上传文件信息
    $ L5 S) D/ ~/ u* j  K! c
  26.             foreach ($info as $file){
    - h! w7 x6 B, A$ M& T
  27.             $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
      j- p, R) G" H
  28.                         $name[]=$file['key'];/ R9 }8 }' }3 e
  29. - Y' O7 @& W# o5 d# o  o! u% u
  30.                
    " J+ b8 L9 z& |9 w' V- ?
  31.             }! M/ o9 r0 j3 t/ z' ?
  32.             //图片物理目录删除、改名图片用
    0 n& l- a+ e3 C2 o. v, r
  33.                         $bigimg=$file['savepath'].$file['savename'];% m6 X) e( G% G" J1 j4 ]
  34.                         //$_POST['goods_big_img']=$bigimg;3 [4 V! _. i0 U3 E# w+ x- W
  35.                         - Z0 b. T$ I" ?4 T5 |2 G" F$ v
  36.                         $ P7 Y; F& B+ A; s3 s
  37.                         $image=new \Think\Image();8 C  ?: j+ ~5 L1 h- h& z& `# w
  38.                        
    $ M+ L- i+ l& z: u( }$ K
  39.                         $srcimg=$upload->rootPath.$bigimg;
    8 V. ?, {4 S4 I# C& Y2 s
  40.                         $image->open($srcimg);
    : S' V% H+ m- D, E3 X" z# h
  41.                         $image->thumb(500,500);
    6 n) G* P3 K# B" m" a3 }: C, _
  42.                         $smallimg=$file['savepath']."small_".$file['savename'];2 s, [/ p9 S/ n3 u4 y
  43.                         $image->save($upload->rootPath.$smallimg);' Q, s. z5 R" t& X
  44.                         //$_POST['goods_small_img']=$smallimg;
    9 B$ c" V: y/ t$ M
  45.            * b) \" R7 p1 @: C
  46. $ H* Z! @9 I3 x8 K4 M: j; U4 o
  47.                 ; L  r8 Y) g. b( k
  48.                         if ($path_old && $img_path) {6 J6 ~1 Q/ t0 `
  49.                                 unlink('.' . $path_old);1 W/ V- j. q+ ?# f. K! Y, T
  50.                         }) c* \: p) [3 R4 d
  51.                
    2 E# m( p0 ~4 r2 L
  52.                
    ( I' I: e1 W) Y' b- k
  53.                         $res['stats'] = 1;
    0 S3 P! v- x8 ?' H1 K; `3 I& h* K
  54.                         $res['res'] = $smallimg;  N3 u) I$ R; V
  55.                         $res['name']=$name;
    7 V" b5 P( W+ U3 v
  56.         }- q' i% L7 e- d/ p9 L+ y: F  W
  57.         
    - I5 Y) @$ x9 e# y  P
  58.        
    5 R, j+ f' g8 E! y6 R
  59. }
复制代码
, g+ S# r2 j1 D! b" a* q  e6 Q

' C8 @8 @8 D( R- x5 {6 I
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 支持支持 反对反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

GMT+8, 2026-1-30 16:45 , Processed in 0.055397 second(s), 20 queries .

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