管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){1 G* c2 F& ]( Q
- $ b$ c8 [- L& X; e @
- $images_path = './Uploads/image/shop/';# G3 ^; Q4 ]& u
- if (!is_dir($images_path)) {8 @: V4 }* i% d6 r
- mkdir($images_path);
& ? ]$ s+ I' R3 g0 P2 H6 @ - }
8 ]0 f6 C' q$ e ?/ P -
5 [+ W) o5 E) h3 | - ! D" T5 N, d& U/ V
- $upload = new \Think\Upload();//实列化上传类
7 W/ [. }2 u9 R3 J H- R$ \ - $upload->maxSize=4145728;//设置上传文件最大,大小; v0 q+ U" G1 o# y& @$ X# T
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
8 V+ r0 q8 ~2 O, p/ g2 k2 j# [ o - $upload->rootPath =$images_path;//上传目录3 O! C" v( E* D! r: @' ]
- $upload->savePath = ''; // 设置附件上传(子)目录
2 F) U9 c" z4 L# F - //$upload->autoSub = true;
) _( p) z! C% ]) i* K- | - //$upload->subName = array('date','Ymd');
" h- D/ U$ U8 x! y - //$upload->saveName = array('uniqid','');//设置上传文件规则
* p8 e. A2 g2 I* H$ M5 M5 s3 a, h - $upload->replace = false;
, U [# X5 c% s( K" M7 N' n - $info= $upload->upload();//执行上传方法
* T$ y# |3 ~' m: O - if(!$info){! w Z+ G/ a" j0 d3 \$ z9 y
- $res['status'] = 0;% l2 e- e9 b( n: | }9 Z0 F, Z( J
- $res['res'] = $upload->getError();6 `* a9 I7 B. g9 G
- 8 I+ [# W8 W; |
- }else {( j8 J+ e; ?& r
- ) F9 m0 h1 U1 Z$ T
- //获取上传文件信息- J2 O& i- @) o. a
- foreach ($info as $file){
, \! b9 h$ V* S1 n7 G - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];6 D9 W8 O+ g$ S
- $name[]=$file['key'];
8 |& f# I! v' K1 f3 J
, d5 z+ G3 U& j1 Y- 5 K% \1 C. T, c# g+ q! t4 K0 O9 o& F
- }
- w# X& R9 K+ `" r, g0 O - //图片物理目录删除、改名图片用- L" \1 {2 L) ~- K$ X
- $bigimg=$file['savepath'].$file['savename'];
2 O& D9 Q2 j/ z. c5 B - //$_POST['goods_big_img']=$bigimg;
0 a: x# X2 S% v3 s$ E) j -
& q: j: ], m3 D# c6 _: r2 V -
% V& }7 C. j( T1 r - $image=new \Think\Image();
: j4 R& ?0 N q - % x- _0 X" [4 T5 J3 w2 Q S
- $srcimg=$upload->rootPath.$bigimg;
5 w' @2 U5 p- k& |# X% A) S - $image->open($srcimg);
3 I. c2 D& v% [) _* a - $image->thumb(500,500);' G; B- C9 W5 U9 M* K
- $smallimg=$file['savepath']."small_".$file['savename'];% b0 Z& E9 x, S$ `0 e' l q. b
- $image->save($upload->rootPath.$smallimg);! A/ [- f$ q0 K9 r" U; H% H. k+ U
- //$_POST['goods_small_img']=$smallimg;' v4 Y8 K* U9 ]$ g
-
/ c8 Z/ F% O; L% S; A
: I0 O; G2 Z1 K E: \/ t-
# ?; k7 W) q; ~+ H' k* @& m/ y4 m - if ($path_old && $img_path) {4 B0 P' T U2 N& j- \9 d3 w9 {5 q
- unlink('.' . $path_old);
0 z2 ]" D/ P# i/ I& P: B- x1 u! r - }
* s. U0 Q5 V0 Y# @ -
) {7 ^( q. L3 W/ k; S% ^8 s -
" \2 I. }. X# S9 C( G/ p - $res['stats'] = 1;
# d& o7 ?4 E1 M0 g( U% o1 B - $res['res'] = $smallimg;3 W: N% R0 \4 b! y$ E: t
- $res['name']=$name;
2 v1 f- V! |5 i6 r7 z - }
+ i- B( Y1 P- m% N# \# Y) r ~4 P - 7 q0 ]2 e0 e6 f
- + ^2 S2 T+ a+ k: K! B5 A# J
- }
复制代码
- W- ]1 R& x+ A% H) \' ]8 S1 H0 e5 _% ]4 B& @1 n; q5 i4 g. ~8 ^3 ?
|
|