管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){2 I: w1 L8 q8 c7 N1 h
- - ^2 o4 |4 c' }% g9 W" T# Q
- $images_path = './Uploads/image/shop/';
- ?3 a& J6 A; x4 g: S6 A: h - if (!is_dir($images_path)) {+ T9 ~9 F4 P5 F% v0 B1 W3 M0 v
- mkdir($images_path);
0 y3 T7 m3 u& d* b5 G$ X: J: @ - }
+ r$ d4 b, [+ j' W) P/ ^2 C. Z9 W -
6 c# J4 J) c6 j) {9 e
0 _2 ?' a* Y) _1 H! U. ~6 |- $upload = new \Think\Upload();//实列化上传类
# P# t$ ?2 k) T$ M& t: ], `* j - $upload->maxSize=4145728;//设置上传文件最大,大小9 k% `# X1 O" x `- L
- $upload->exts= array('jpg','gif','png','jpeg');//后缀8 J) q8 e8 X) D% R3 ?, R, b3 k
- $upload->rootPath =$images_path;//上传目录, g: u7 w; t/ P) r
- $upload->savePath = ''; // 设置附件上传(子)目录9 [6 V* {" `% I& L* G# A' `. }6 B
- //$upload->autoSub = true;& y6 A) O! ]+ O- M! F& V5 Y
- //$upload->subName = array('date','Ymd');& h8 _: `0 [- E
- //$upload->saveName = array('uniqid','');//设置上传文件规则8 b4 ^ u$ I& r% Z3 q
- $upload->replace = false;5 X( e: A1 F& X* G
- $info= $upload->upload();//执行上传方法6 c" |8 o. V# v9 c4 f s- n
- if(!$info){
+ i- e" C* W9 W9 g8 o; f - $res['status'] = 0; w1 @$ ~4 |9 t8 {8 t' u# H6 W
- $res['res'] = $upload->getError();
- C/ @% o$ b& c/ I/ N - 0 D" l0 M- Z* |2 `% ~
- }else {5 `, _& w5 b3 p) s" T+ T
-
: U# [- f4 v7 P' ?9 M7 u9 G - //获取上传文件信息
0 l# G0 f( e$ _, Y: U u3 K/ Y - foreach ($info as $file){# @: L% u/ A) q4 J
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
% F) y, k! G5 F; s `( o - $name[]=$file['key'];
/ Z9 I- u. D+ q# U$ n - , Q8 C, M' S1 A: ?
-
% t3 B: ]$ z9 O; s0 l - }
& b3 D' j; |9 B3 [$ q; s! y - //图片物理目录删除、改名图片用
" k/ H- |$ V8 M4 {* D) K. b5 I& ` - $bigimg=$file['savepath'].$file['savename'];$ `! e1 l/ K0 C' S# q
- //$_POST['goods_big_img']=$bigimg;3 l$ E) }. _- o5 o; h- ]/ A
- 0 x# ]! b# [1 j/ |
- 0 V+ b7 ~" H7 S. c. t% x# Q: |" X' H
- $image=new \Think\Image();& i) [4 }% g& o1 z2 x' r$ p8 X( I
-
, t' `* p/ y& B; U/ ]+ J - $srcimg=$upload->rootPath.$bigimg;
8 g- f6 e2 J3 X T2 ?2 E) Z4 K; p - $image->open($srcimg);4 O$ i* Z* \* \ ~
- $image->thumb(500,500);
w0 [0 P2 E$ ?0 r - $smallimg=$file['savepath']."small_".$file['savename'];# H2 Q* i' o7 [2 o
- $image->save($upload->rootPath.$smallimg);, L5 N( W- k' x7 P2 l- \2 j
- //$_POST['goods_small_img']=$smallimg;
: N$ {7 x$ v- S/ u9 e5 o+ t - 0 t; ]2 m i, N) Z7 M; W
% k# f; T& d- {& ?( B8 s2 j- - @5 o% v( ]" |) |3 T- W6 x
- if ($path_old && $img_path) {
4 Z2 ~' A/ {, i - unlink('.' . $path_old);
- C" c$ W- i# g) B - }
' P, p, d" h: D* g) K* t! y$ ]% V/ e2 n -
( E% N, L, X' x9 Z) Q3 w/ @ - & T1 T$ k9 L+ L7 x
- $res['stats'] = 1;' c# o6 ]) ^7 f
- $res['res'] = $smallimg;, s* _* O3 T9 b
- $res['name']=$name;) _ y7 X: A+ n+ x' `
- }
! B2 p& H; l! Z4 ?& J- ` - , |$ ~9 _' T$ J% l X6 W
- 0 t8 y; r& i8 r2 W, M2 U
- }
复制代码 5 z3 O0 `6 E( a- F m+ U
/ _% W& {' J) ?7 E |
|