管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){9 n( C) ~; S, Z( R
-
4 L9 I+ ~' E1 a, T7 k1 J - $images_path = './Uploads/image/shop/';
+ S$ t8 b k7 x. A& m - if (!is_dir($images_path)) {9 T2 X/ f" z$ n( _! v2 D+ f, w7 I# f
- mkdir($images_path);2 P) }) h# B2 @" ]- n) U/ _4 A# m6 W
- } / e; l3 g9 z( ^' r% v
- : d% g: [( @; s" Z2 T+ P
- + s; Y# d2 }3 M$ g' b
- $upload = new \Think\Upload();//实列化上传类9 [: I% q+ t1 j& e ?1 d0 S
- $upload->maxSize=4145728;//设置上传文件最大,大小
9 e8 V# g& \- [; l - $upload->exts= array('jpg','gif','png','jpeg');//后缀( H' E V* p5 @3 O8 g' C
- $upload->rootPath =$images_path;//上传目录' k/ S- Y# l( w% Q
- $upload->savePath = ''; // 设置附件上传(子)目录( _, C7 V! x, [$ [: `4 ?% X1 |, n
- //$upload->autoSub = true;
# Z5 @3 L2 H1 C- B% y' A - //$upload->subName = array('date','Ymd');% N% }+ U3 U7 R0 h0 `
- //$upload->saveName = array('uniqid','');//设置上传文件规则
0 e7 x& A; e* _ - $upload->replace = false;
7 j2 v2 G" r/ i6 F: \2 A- J M0 y - $info= $upload->upload();//执行上传方法
% V- e4 l' o' J% v4 b; n - if(!$info){) o1 F0 k, r1 \) E, a6 z' Z. F
- $res['status'] = 0;; @4 A; a4 o, v. c
- $res['res'] = $upload->getError();
6 D" j1 j1 x) _+ w# p/ d -
+ d1 R+ A6 I0 L! i - }else {
9 L# h2 t+ r" F. ~ - ( `- ]6 R1 u' S( u. v7 K8 l
- //获取上传文件信息& Z" C) Q/ }1 E4 g( f
- foreach ($info as $file){0 Z/ l$ y3 g6 u% B9 |
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
% j2 g4 a7 N7 G, C8 F. r6 D( G - $name[]=$file['key'];
) `8 g8 @5 [! e/ ^
6 h0 d2 c5 m3 z! y- ' O. s/ h' ^+ R7 |+ ^% ^; V
- }6 J8 V0 S0 ~' P, V* ?! ]0 N0 Z* r
- //图片物理目录删除、改名图片用% K( P" h1 o" b2 Z
- $bigimg=$file['savepath'].$file['savename'];' n/ [4 B0 k1 x* [. r1 A) p5 S
- //$_POST['goods_big_img']=$bigimg;/ X' G, h0 j% }# y
- 3 k7 l; A$ q1 w7 u, d" r' ]7 d* \
-
0 {* d4 ^+ U8 U7 [ - $image=new \Think\Image();/ G% P. D' c+ [+ Y4 }) \
-
. T# ^4 e/ F; r7 t$ N - $srcimg=$upload->rootPath.$bigimg;& {; w& S7 M6 g4 p# V
- $image->open($srcimg);+ z9 n+ O) _8 k( i
- $image->thumb(500,500);
9 d9 o3 ^. N, X. B u( K - $smallimg=$file['savepath']."small_".$file['savename'];. y& u; @ U$ T9 X8 v2 [6 n
- $image->save($upload->rootPath.$smallimg);- f+ K( H5 q4 ~7 X6 ?
- //$_POST['goods_small_img']=$smallimg;. n$ V5 r6 m. V! s, T- p0 ~
- ) T4 }- k, C! C# o+ ]$ c
- 4 t* c$ N, U' e" g; o1 V. d
- ; _0 E8 `+ G7 h+ g
- if ($path_old && $img_path) {% c, r7 d4 q" {2 D" ~
- unlink('.' . $path_old);
, ~2 ^4 s0 N2 m' e9 w - }6 k$ C9 M; U) p: c# T' \, S
- - K, K: C* r% R5 P2 Q- C, E0 L
-
& ~7 T* I* R$ u - $res['stats'] = 1;9 {. ^, y$ q& M0 j& G) `
- $res['res'] = $smallimg;
7 h( }. R( N+ ^7 z$ M3 N1 f - $res['name']=$name;
) }7 @/ V9 g _: P, r x - }7 N9 i- w2 s' O- {/ C' r L s
-
; _4 p6 r4 o+ t* h& ~/ D# } -
; n5 t3 M/ B( e z6 y - }
复制代码 ( u2 h- Z' V' I7 Z; K6 u+ u7 I- W
+ R/ h9 x% Z5 ~. D. [
|
|