管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){ J) `0 n" {& K1 @- P: {7 T1 y
-
! \4 ]% P- J" C$ W9 I - $images_path = './Uploads/image/shop/';) E) `# Y2 o) n
- if (!is_dir($images_path)) {
( A6 }' A/ {1 V; g: X: t - mkdir($images_path);
7 X# V0 O5 u$ I - }
, P+ d* Z0 q, p9 v1 w' W - # w8 D$ y0 g" w6 r
- 0 U. j1 I: ?9 b* T5 J/ x
- $upload = new \Think\Upload();//实列化上传类2 ^7 G& S4 n, G8 K
- $upload->maxSize=4145728;//设置上传文件最大,大小$ c5 X. x* Y p' a% k5 N
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
: q/ Z& H9 u3 m1 e - $upload->rootPath =$images_path;//上传目录
- P5 t' |8 \, H6 q) ~9 c C& F - $upload->savePath = ''; // 设置附件上传(子)目录4 ^$ p# {" W: n! D- W$ | y
- //$upload->autoSub = true;! I2 G$ y. ~" T2 o/ M R: h
- //$upload->subName = array('date','Ymd');
( c, w; a# E7 P$ ~ - //$upload->saveName = array('uniqid','');//设置上传文件规则; d% p8 e8 c& @; v) \
- $upload->replace = false;! k* n: a, e2 Q q
- $info= $upload->upload();//执行上传方法9 m, Q( z: \7 N+ k3 @, O
- if(!$info){
& ~1 s+ s; l$ b3 \0 b7 U; z - $res['status'] = 0;% |% s6 z& h8 m; }! p
- $res['res'] = $upload->getError();- f. t" L, Q" Q# S6 i* a# F' F
-
& s! h; r: X7 j - }else {' S- A* u/ I' E, ?) C5 N) j
-
" a' A8 e1 K- z+ U5 K' U& o' ~# l' f9 R - //获取上传文件信息/ {+ g) v/ U% j! z& P: u
- foreach ($info as $file){1 x7 ?' t% B$ Z. C; o2 j1 f
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];: f7 O' D% y3 L, y- s+ h
- $name[]=$file['key'];
. _6 C- T: D& C; U! R6 v$ v - 0 u! }9 M( _% G$ B
-
0 r7 k5 n! h- r/ U. X, l - }
9 e0 a% i; W" g& s - //图片物理目录删除、改名图片用
. R- a+ E$ w5 K - $bigimg=$file['savepath'].$file['savename'];
z/ @4 o% O0 w5 S/ \0 ? - //$_POST['goods_big_img']=$bigimg;
# |3 q/ {; N- g$ I - W& g5 Y* p4 p2 t8 ~& r# Y
- ( _8 V P( q) Y1 G9 j' i& O# A' C( W
- $image=new \Think\Image();, ?, G( { i* L
-
& x: ]+ T/ m: z& N1 {6 D/ V - $srcimg=$upload->rootPath.$bigimg;. c; \* Q$ f! ]0 x) R6 b9 V5 `
- $image->open($srcimg);
0 q5 r* S9 o/ U* ^. N - $image->thumb(500,500);
+ n" J! S( S- L1 ~ - $smallimg=$file['savepath']."small_".$file['savename'];
1 z) n' i+ ?; Z/ k1 n6 g0 W! G - $image->save($upload->rootPath.$smallimg);
5 W; N0 D. @; k( s6 V - //$_POST['goods_small_img']=$smallimg;6 }% w, Q/ f! F- G" y2 S* W& A: \
-
; t8 H' r6 C5 h& a1 `5 D1 l0 S
! L, I U v! T- / O% J; i7 Q% ]. Q
- if ($path_old && $img_path) {
: _; \1 \- A8 U; ? v1 g' D2 j - unlink('.' . $path_old);' N) y P V5 |: C5 g( A; E
- }
7 L* w) }' K" S8 w; | - 8 I1 f k4 P4 u) K+ ^
- 9 N2 L& i3 E# f Y' k3 R
- $res['stats'] = 1;) ^. t3 m% K3 o# | Q+ I7 T6 M5 O
- $res['res'] = $smallimg;) \' n6 v" J" e0 `+ t( ^. j
- $res['name']=$name;
7 N u. p2 ~/ a) M, Z. Q* j - }- F; D( `6 A) d; P
-
1 W, s( v" }' u -
/ E# s0 r/ G5 f! Z7 o. w - }
复制代码 / F5 a+ p2 X' V# @, r
) R* I7 [$ O. @5 r, V" M s
|
|