管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
) t" ?5 c$ W9 E% l+ x" W1 _ -
: u5 M7 }# T' I' c( U - $images_path = './Uploads/image/shop/';4 b x$ s0 Y+ q2 o% \
- if (!is_dir($images_path)) {
" m) [% U' u# l' e, b m - mkdir($images_path);
7 b/ D( p' Y0 q - } / V7 D L& [' W, y. t' h
- 9 S, @6 Z5 s8 B4 @/ I) O* H
- 9 r0 H2 M& h+ U- P1 q Y5 p
- $upload = new \Think\Upload();//实列化上传类) ~ _6 b3 \; \: _- W3 n
- $upload->maxSize=4145728;//设置上传文件最大,大小
. N, `( A4 M) ~4 E - $upload->exts= array('jpg','gif','png','jpeg');//后缀
- P5 a5 `$ J- O+ a - $upload->rootPath =$images_path;//上传目录7 P2 Q, V! a% N: f# ^/ i$ w+ Q
- $upload->savePath = ''; // 设置附件上传(子)目录1 ?+ B6 t" s0 V$ L3 ]% S1 j
- //$upload->autoSub = true;- n& F4 w; _) D8 P
- //$upload->subName = array('date','Ymd');
; |: {4 ^" \/ q: i3 N! o0 \ - //$upload->saveName = array('uniqid','');//设置上传文件规则7 U8 B {7 ], X
- $upload->replace = false;
& H$ ]; o6 ^ h1 F* P - $info= $upload->upload();//执行上传方法
) _! o2 l2 F: O - if(!$info){
# q2 p( T. l3 t& o- h; ]$ @. z - $res['status'] = 0;1 q- W P3 e/ D
- $res['res'] = $upload->getError();
) J% E7 b5 f7 x+ k- f8 n -
8 w; X% l3 X# ^5 |5 W* Y - }else {
0 s. i5 ?4 O' f& U$ Q, c - , K/ o! ~0 @0 v; ?
- //获取上传文件信息
4 V/ J4 ~+ ^! H5 [' [ - foreach ($info as $file){
$ N/ }% C2 E. r. ?1 w, i - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];. [7 v- }+ x [8 \" U% L! u
- $name[]=$file['key'];6 N5 y U0 Y/ H: ^6 ^) C
' B+ h0 _; O& O+ o/ [& O- # k9 a! I- x( Y+ K/ @- W* U& E
- }
# n4 K: d/ t, G* Q - //图片物理目录删除、改名图片用# ^5 C* v1 r# T, M& G
- $bigimg=$file['savepath'].$file['savename'];
J+ S$ k7 N7 g& @; R# U9 E4 i) b - //$_POST['goods_big_img']=$bigimg;$ z6 B1 K5 t2 l3 a5 `/ C2 H
- ; Q8 P8 ?: T* l2 ?. ]9 y
- 3 k q1 R6 T2 v+ W- t
- $image=new \Think\Image();
& E: i2 b U; K0 P$ c -
" O3 G) z9 l; A, y3 j - $srcimg=$upload->rootPath.$bigimg;
$ U2 p% W' Y1 ~5 O* _% a- A( A - $image->open($srcimg);. l- r2 q) J# e8 _
- $image->thumb(500,500);7 M! P/ o( m! U! H4 k
- $smallimg=$file['savepath']."small_".$file['savename'];' Y9 @" P! T3 C
- $image->save($upload->rootPath.$smallimg);
7 Y: L" v1 U' D( W! q# e0 d: ] - //$_POST['goods_small_img']=$smallimg;
; w C; C9 x1 D7 z8 L% D1 C5 } -
@4 ]' x7 x: v - ! C7 ^2 X$ g T+ u, ?
- . n$ t1 M( x- I9 s! o
- if ($path_old && $img_path) {
6 r6 Y6 c6 k4 S2 {3 v - unlink('.' . $path_old);
" b H; _8 V8 G - }' {5 L( @) z1 E6 E0 Y u
-
% I5 S5 \7 b& s' C! e/ Y -
3 L( x* ^; D- A' C! l - $res['stats'] = 1;) I3 x) C# ~. ?& }3 L9 j' v
- $res['res'] = $smallimg;3 S( b+ @0 |5 X$ t' n' R
- $res['name']=$name;+ V, n$ n' f z
- }9 v4 ]; L5 U: _& e! [8 J: Z) z
-
8 `$ ^/ T9 G+ J -
: X9 ~ P4 d& m) g; p - }
复制代码
+ f# b0 M! S2 Z
- X3 b6 n/ N5 x& X5 G9 E9 A |
|