管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
+ t L9 L N9 a* A - 5 ~% Z8 m! d' P5 O( k" g+ g7 |
- $images_path = './Uploads/image/shop/';
4 f$ H/ z$ m7 n5 `1 H- M+ T( S - if (!is_dir($images_path)) {
1 x9 [6 O8 Y# r; K" l X - mkdir($images_path);" ?4 n6 f1 p6 y- s; a
- } . r: s! Q8 m) W; y6 W
- 2 S- \* [3 i% [/ I6 j% e* o! N
- ! y* w% i- j& b/ q# B2 Q' t
- $upload = new \Think\Upload();//实列化上传类* Q& \+ i% V6 L6 C4 I8 c0 @7 c; G& O( ~
- $upload->maxSize=4145728;//设置上传文件最大,大小
; o# O" v( z0 \8 {/ V' W# p; i - $upload->exts= array('jpg','gif','png','jpeg');//后缀
( u+ l) s Y5 R3 ?4 s1 U - $upload->rootPath =$images_path;//上传目录; T/ e% G4 w" u9 D
- $upload->savePath = ''; // 设置附件上传(子)目录6 D6 y7 R- }+ d+ S
- //$upload->autoSub = true;
5 r5 j( }* Q1 y2 h( W - //$upload->subName = array('date','Ymd');# M5 b1 @# }) W2 ? ~$ }: M
- //$upload->saveName = array('uniqid','');//设置上传文件规则+ [+ G- b' c& U" B7 x0 O- s
- $upload->replace = false;
/ F# p; |: d* F+ O" ~" M4 n- n - $info= $upload->upload();//执行上传方法
3 v- T% u0 `$ g$ D8 s6 a) R - if(!$info){
1 V4 Z4 \ A* e# M$ `: k, U - $res['status'] = 0;1 A0 u, k6 N2 I9 {/ R$ Q3 w
- $res['res'] = $upload->getError();5 C$ W" F+ ~. c. L
- . M7 c7 I' z! l+ M) \$ q
- }else {
2 [* K# q- t0 S0 w - # @8 V1 Z9 X- ~/ A% e
- //获取上传文件信息
9 |2 a, }0 n( O+ f% [* g4 d - foreach ($info as $file){
6 ]+ t, @2 e- x - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
+ H& B. o% o0 y. Q, J8 {! {# ~ - $name[]=$file['key'];3 z; J$ I# i8 @9 x
- V# Y: |" n: r/ }% g" _- ( A+ |/ T' i& b& h% Q5 Y
- }8 z) v% u7 @) P; L
- //图片物理目录删除、改名图片用
2 f, B) C( Y3 g3 d; } - $bigimg=$file['savepath'].$file['savename'];
W6 V! ]2 u! ]& N; y( n - //$_POST['goods_big_img']=$bigimg;
v$ l: s$ @: M. M" y0 y -
* e* E$ ~* J5 o4 T - " \% \& U$ B% `
- $image=new \Think\Image();
. ?' P! s* Y; Q+ x. D& W; b -
B% M+ F# j [$ U0 F' a$ j( ^ - $srcimg=$upload->rootPath.$bigimg;" u* u. V7 k+ r# a; u
- $image->open($srcimg);
# Z+ B) X+ E! h5 F4 _) f, Z - $image->thumb(500,500);
4 k. }; q. W4 `( X6 l) g4 \ - $smallimg=$file['savepath']."small_".$file['savename'];
6 }& d) W ^; _$ U - $image->save($upload->rootPath.$smallimg);
4 I$ q g% ?) m9 f. ~ - //$_POST['goods_small_img']=$smallimg;
9 w: X# y/ k! T3 W3 x+ D: I -
/ u: M2 x# ]/ j- o - v6 V0 N3 ] V4 N7 {
- / p4 ~$ v6 `4 b* z1 p- j( M# S `
- if ($path_old && $img_path) {
9 i1 b0 @2 j7 |; A - unlink('.' . $path_old);
' U& Z9 K; i9 Z1 M7 ? - }
& D8 D- s0 q2 P. r# h -
$ _! S2 F' N8 e6 }/ \6 Q -
* B. J6 b$ V: T0 n - $res['stats'] = 1;
! F9 Q' ~: Y& n0 r" b - $res['res'] = $smallimg;
9 g6 z: o3 g! C6 e7 J) M( A) ]: ^% L - $res['name']=$name;
0 H7 K: O' Z1 w0 | - }
9 l4 Z0 Z2 M& F6 K -
( g8 X7 w& M: D' d* L: O - 2 j6 S. ?5 i$ D" H
- }
复制代码
- j+ Z e8 O" P9 }: C3 d0 `1 W8 C& h) h- N6 t3 F
|
|