管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){7 l5 k$ b0 t, a+ r% R. N: L6 @2 B
-
& e( q2 t3 T5 j& b - $images_path = './Uploads/image/shop/';0 ~# l5 \+ f; \: D; v1 i4 P
- if (!is_dir($images_path)) {+ Z2 h- f' E$ I" Z6 R
- mkdir($images_path);& E4 }& N- O+ y8 B1 B
- }
+ O6 f% {' c5 r1 q: d5 _/ i* O" g - ) Q# Y9 e4 \, R7 R7 B' a
- $ ?9 C0 \4 i+ }: t- L% `9 N. s. T( K
- $upload = new \Think\Upload();//实列化上传类( _" G, a! L L% E' _: _) g7 i& n
- $upload->maxSize=4145728;//设置上传文件最大,大小; a6 O. r! m* X
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
1 G+ k @' S: n3 I5 q - $upload->rootPath =$images_path;//上传目录. f3 {. d3 O! p$ V& Y6 H; f& d t' X
- $upload->savePath = ''; // 设置附件上传(子)目录; f" w {& |1 i
- //$upload->autoSub = true;, ` N3 x7 B7 E5 r H. ?
- //$upload->subName = array('date','Ymd');1 r3 g* A6 B) O. H5 B6 U' d- a
- //$upload->saveName = array('uniqid','');//设置上传文件规则- O3 i6 L& c* g+ B
- $upload->replace = false;9 |! G" }8 D9 g
- $info= $upload->upload();//执行上传方法
$ c0 g# @" U' z ^ - if(!$info){
# L6 u0 C: z# W; J0 ^: ? X - $res['status'] = 0;
) K' N {1 D4 v5 g G! N - $res['res'] = $upload->getError();$ |8 @7 A% S c% X' T
-
3 C; @0 m5 f' x% `$ g' D - }else {( ?+ [ q' n$ _% T7 R
- 5 u+ T0 p# |6 R2 Y$ ?
- //获取上传文件信息; b% |8 C d" j6 ?( L( L: B
- foreach ($info as $file){ P5 s0 i, l- g
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];3 f* s1 v, q% m, k% s! L- a& n
- $name[]=$file['key'];
+ I. Y. R, q+ ?: J2 }# F9 i - q' G) {' X- @' e4 V" f9 Z
- - ~. P1 [& {) W/ q$ z
- }
4 \6 w, d$ s1 U) y% S" S - //图片物理目录删除、改名图片用7 N7 s# }' J; u7 ]* D
- $bigimg=$file['savepath'].$file['savename'];* n, B% b4 |. g. o) ^& U& v' c$ I
- //$_POST['goods_big_img']=$bigimg;$ G1 S3 u, i) ~1 w3 t( [6 }3 l
- ' @7 }. O. k. {$ H" s4 L
- * |- u y; i( r" @7 y h3 F( f
- $image=new \Think\Image();
! q, h" q& k0 u& c# y& E - 4 |0 E0 ]! w5 h; l; |
- $srcimg=$upload->rootPath.$bigimg;
5 b6 c* \: P7 J6 G' _+ j e# k - $image->open($srcimg);
2 J9 n5 b: i- G4 P - $image->thumb(500,500);
& |' y9 _5 A2 N/ ^$ Y - $smallimg=$file['savepath']."small_".$file['savename'];$ ~! n$ J. h: e0 v d. D. v9 {3 p
- $image->save($upload->rootPath.$smallimg);
( u+ z# Y# s; u1 s - //$_POST['goods_small_img']=$smallimg;: @, i6 Q# F8 h7 ~
-
0 w, x: ]; Y8 [/ x% g6 M
3 z8 z" g+ L3 o1 N, B& y/ r: O- , Q& ?0 E3 B6 P1 Q# }# |
- if ($path_old && $img_path) {
3 ^+ p, c/ Z4 D/ L4 s; K! | - unlink('.' . $path_old);& I' j5 Y5 W5 M4 ]. ^
- }, K- E* J/ A+ \
- 7 N; ?4 |; N8 D
-
" p' a! i. q, }' M* r' S0 u# \ - $res['stats'] = 1;
6 n8 l) x# K2 i$ x6 f - $res['res'] = $smallimg;
1 h/ V+ ?0 u U: b0 ^" j4 p( l - $res['name']=$name;
0 m: a2 {* o: u8 m/ Y3 \3 O- N - }$ o7 a5 g% p$ N2 k
-
; f l% ]. k- P* S/ g# ` - |- v# G* b' Y- B8 g8 P
- }
复制代码
) C4 D5 J7 ?* S/ m; o* b% I$ E3 R/ M( X! K
|
|