管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){2 i3 z) p0 q7 u2 S3 e4 d% }+ n
- : ~/ J+ I1 _$ R0 f( \, K. K
- $images_path = './Uploads/image/shop/'; L3 x) G, ~( E1 _2 e9 b
- if (!is_dir($images_path)) {
/ e3 [% S* _# L# U - mkdir($images_path);
$ h/ r2 @- T, S/ N0 q - } - y" Y' _1 g& x* f
- . F7 j6 ~! r$ J" V
- ) a' A3 o9 f0 U3 A8 R; [
- $upload = new \Think\Upload();//实列化上传类5 l/ _* d/ L' [9 o3 T
- $upload->maxSize=4145728;//设置上传文件最大,大小
$ r, t0 O3 |. w, v - $upload->exts= array('jpg','gif','png','jpeg');//后缀
3 a( H% b) U" W1 `% |( s" O l) x3 s% Y - $upload->rootPath =$images_path;//上传目录
" n1 j0 L7 v; k, T8 ^$ h; _, R - $upload->savePath = ''; // 设置附件上传(子)目录) d& z+ O, z% u$ Q
- //$upload->autoSub = true;+ Z/ h' R$ {$ I" W, R
- //$upload->subName = array('date','Ymd');
1 B/ a" ~5 B7 _8 M# K2 s - //$upload->saveName = array('uniqid','');//设置上传文件规则
% e7 j7 ?# Q) i B+ b- m" C& U - $upload->replace = false;
. e/ f$ a! P2 W5 e/ F. s* N - $info= $upload->upload();//执行上传方法& F$ a# I0 `5 z* W+ M% X& F9 l
- if(!$info){% r7 d C+ A/ L. { h2 a
- $res['status'] = 0;
' m; Q4 C2 T( F$ e$ x7 y: p - $res['res'] = $upload->getError();: f0 I5 C+ r# [) H7 D+ P @) a8 i$ s
-
2 x' C4 O; D8 ~/ {% E - }else {
! H1 w" Q9 k9 q) U4 i. l" J j -
. Q2 V3 e( u: y% ~, t8 D) [ - //获取上传文件信息
) |2 I9 p+ j% g6 o+ Y z - foreach ($info as $file){
# j5 V$ f8 W3 O+ Z- [5 h: b: g - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
8 H8 \& l/ `, p* q& h$ `" | - $name[]=$file['key'];
2 W6 O( z( p; K& m! ?; r2 _
+ P& U" G' K: ]0 y- / b+ [2 s% D8 }; Z
- }6 S7 z2 q+ d' N% A/ O& Z
- //图片物理目录删除、改名图片用
" d7 I( k( X4 J9 I - $bigimg=$file['savepath'].$file['savename'];
' r! B/ e3 E+ h# s - //$_POST['goods_big_img']=$bigimg;
, _2 Z P- @2 u# \! }& H' y -
" }: p6 E2 ?2 U4 K3 N/ q: j6 H8 e - / g' s. A; @2 E" w. Y
- $image=new \Think\Image();
; `. a3 R4 S' c3 j -
) \# V |( \6 O9 w" q/ N. `, D - $srcimg=$upload->rootPath.$bigimg;; L3 _) E+ [. V) w% }
- $image->open($srcimg);
2 x( D' x" v% ]8 X0 \4 u - $image->thumb(500,500);; E) F5 I: i1 j D
- $smallimg=$file['savepath']."small_".$file['savename'];+ b8 G, H! e+ v8 d" E$ Y9 w* q; I
- $image->save($upload->rootPath.$smallimg);- z2 B' p1 H- n) K2 a( `
- //$_POST['goods_small_img']=$smallimg;
/ C& u0 M/ l# d, N - 0 j, t' M, S9 r7 |/ y0 `
- 3 ^8 s. d- c# l: p
-
' @4 B) Y/ [2 B. \$ J( s z - if ($path_old && $img_path) {
! _2 S: t" {7 }2 K - unlink('.' . $path_old);
$ J( [- Q4 z4 e8 C - }
/ Z: N! t& I- V' o: s - 1 z. Y/ p' L" ?# R! z7 |4 ^4 t) b: h
-
0 p2 @; m% d* c* E( D6 Y2 _ - $res['stats'] = 1;# f: T9 _1 r+ w1 i; H! t
- $res['res'] = $smallimg;
" ]) E1 D! v; y- R$ b1 n* n - $res['name']=$name;/ D, M2 X" `* [: P1 _6 y
- }
3 X5 P+ N' d. R4 d% r: ^ -
0 c; h. ?. y B -
! g5 o3 f" C& P1 ] - }
复制代码
) O9 @; X& \ u3 s/ E; d
+ l$ c) z- S6 f: Y+ m |
|