管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
0 C+ K4 J5 s) `7 v9 j& h - ( ]. B2 W: c y
- $images_path = './Uploads/image/shop/';( [* f: b1 b* s7 m& B
- if (!is_dir($images_path)) {
& j& ^) ]% J% j/ ` - mkdir($images_path); K P5 K% N. B
- }
4 ^9 y& {' x9 p* C4 e$ X/ n/ b -
9 L" [& J6 A+ z% Z* r* S' w - ( E. z0 ^3 N* `# }4 y( x
- $upload = new \Think\Upload();//实列化上传类
" p9 I$ X% y) `) K# y - $upload->maxSize=4145728;//设置上传文件最大,大小0 P- ?+ ^ k7 I8 j' u; V/ W
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
; O9 r4 J9 a# @4 }) Y% o - $upload->rootPath =$images_path;//上传目录) N& N! C7 V5 `5 I# p
- $upload->savePath = ''; // 设置附件上传(子)目录
! p N6 y. C ]* N& C1 w( x; q! \" v, c - //$upload->autoSub = true;
4 p/ B1 J! E9 f8 Q' {3 H# g4 n- M9 g - //$upload->subName = array('date','Ymd');$ ~5 F6 a) b. V% n" Q
- //$upload->saveName = array('uniqid','');//设置上传文件规则& n# R& g4 |8 c7 E+ x7 Q
- $upload->replace = false;; c7 l! {" g4 [
- $info= $upload->upload();//执行上传方法, P. F* W. V" t( F; T
- if(!$info){
; J6 Z, X1 Y2 x$ ?! o - $res['status'] = 0;
" \3 E$ m; u7 j - $res['res'] = $upload->getError();& U/ Z6 W! n$ K5 y
- $ W4 V1 n# Y0 D* s L7 d4 v2 ?
- }else {
" [. e J$ h# y# h4 d -
6 R5 g0 C/ k( _: m, y- X - //获取上传文件信息
4 N: I; @5 K( c F2 m5 m7 Y - foreach ($info as $file){7 Y( B1 `0 g8 z% k0 e
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];% E2 O" J* U" J9 T1 d! K
- $name[]=$file['key'];
+ M5 A8 b4 j: d! l3 w# d4 b - ) a1 b* [3 Y- J
- , O7 ]% {& c' P: }( I
- }9 t$ T) k, ]# A1 S u
- //图片物理目录删除、改名图片用( C& H" e& u% g9 `0 l
- $bigimg=$file['savepath'].$file['savename'];5 S. J4 u2 ?# \" A6 @# c- j/ K- ~/ }
- //$_POST['goods_big_img']=$bigimg;: o$ w4 e3 K% A$ @3 r" p9 S, u
-
4 k$ V. c5 }. Q& }8 O+ K" M - 9 R8 j4 _: v; F$ \9 P: y" D
- $image=new \Think\Image();- U y. R5 A7 m0 c, ^- h6 U
- : v1 [: z& r7 x. u0 X" o
- $srcimg=$upload->rootPath.$bigimg;
. ]* K5 o" R: }; @ - $image->open($srcimg);
) y2 Q. C. l! f( T: L: Q% q$ y - $image->thumb(500,500);
1 ~5 l; T" \ ]" G6 s) p - $smallimg=$file['savepath']."small_".$file['savename'];% j0 Y! b% Q- z. s
- $image->save($upload->rootPath.$smallimg);
! u, U' v, p" g- s- \# J; ?) s - //$_POST['goods_small_img']=$smallimg;
5 K, x3 C+ Q! A: u# a/ G -
8 Q( l. Y3 ]' c) I% d$ H- @
: r7 o$ f" a0 O+ X7 z- \; m- n-
+ U& S' @0 M/ p- X1 _+ r$ H! H7 d - if ($path_old && $img_path) { X+ T" M$ m% {( R. U* M ~+ @
- unlink('.' . $path_old);
9 j- t8 C5 y( }6 k) l) Q - }6 ?0 ?8 i: L1 L! d* s4 {
- 1 N, q! q$ D2 L w3 L" Y
- ! \& e6 T+ b+ G' j/ G4 U; X s' G
- $res['stats'] = 1;
9 _& `- w6 ~. N# B3 N# t' M - $res['res'] = $smallimg;
4 s, ]' d* f* t, V - $res['name']=$name;6 r9 Q- x* @* a2 ?2 r' M
- }
) ]7 F6 i: D s7 b5 J - 0 y$ K5 K! Y- Q% j* z$ G9 @9 U/ c& A8 n
-
) E. d) F- g& A7 R8 e/ D - }
复制代码
; v7 ]! h. l- N5 g, v1 y! @( f2 L: t) p
|
|