管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){/ q1 A7 h5 {" }3 J; X& T
- ; r. k; Q* q. s* g6 Y- Y5 c
- $images_path = './Uploads/image/shop/';
0 K' b" B$ d% ]! Z4 W8 ?7 n - if (!is_dir($images_path)) {
$ _( e2 @' Q' R, ]* {- M! }; H) k5 s - mkdir($images_path);: h% L# D" X9 f, m
- }
8 u7 e+ }2 }0 _2 _! T+ } -
+ N6 T: P7 n2 o2 ]8 ]
3 Z' w4 g4 F( R, |+ M5 x; P- $upload = new \Think\Upload();//实列化上传类1 F& l$ C% a8 B3 q7 _( h
- $upload->maxSize=4145728;//设置上传文件最大,大小
$ T# q: }, N7 k/ l8 n - $upload->exts= array('jpg','gif','png','jpeg');//后缀
9 K# Z8 X; r( ]1 Z - $upload->rootPath =$images_path;//上传目录* ]& s/ e- Y, I3 U, `# \/ u2 d' \
- $upload->savePath = ''; // 设置附件上传(子)目录
% H6 k; |& }3 P+ b8 J4 m - //$upload->autoSub = true;
& K+ m" B( ?" h" n6 Y' [ - //$upload->subName = array('date','Ymd');
: c) \! d6 z) `6 G - //$upload->saveName = array('uniqid','');//设置上传文件规则+ f; y$ v& ^: W
- $upload->replace = false;
1 ?2 b: g2 y! U8 e6 k - $info= $upload->upload();//执行上传方法; ]2 O! r; ?6 v* i3 C) e1 m
- if(!$info){
: L4 b& b+ h# Y/ X+ ]- a - $res['status'] = 0;
7 @+ X9 r, U" k; q" O5 v - $res['res'] = $upload->getError();; j* ?4 }/ _8 W1 X) H- d6 o
- 9 v5 f" K m9 i/ }4 t" G
- }else {
: {6 q5 S/ x: p! j2 U7 [ - ' j; |0 I% `) j* S4 F O
- //获取上传文件信息3 g* e. Y8 D6 k
- foreach ($info as $file){7 U7 M0 M" @% e
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
! w* S" o& v, |7 b3 u - $name[]=$file['key'];
) N/ {6 p' P% n3 S
$ u6 n q8 h. T/ u$ _- 0 l% `4 ]+ }+ u# h/ ]8 |
- }# Y5 `5 O/ _/ ]$ y! z( i
- //图片物理目录删除、改名图片用
) e( k9 |, L! @$ P5 n - $bigimg=$file['savepath'].$file['savename'];
" E! d) {9 @* | - //$_POST['goods_big_img']=$bigimg;
/ V: d: T$ f( o- N! k& {5 V# c( J -
$ p3 p% c: e5 Q+ Z* y! s9 \% ~' u -
4 x2 n z; Q' L* o# X - $image=new \Think\Image();
5 L. U0 a5 G6 V -
7 I4 |8 G0 C- x: \ b- |+ Y+ }/ U' w - $srcimg=$upload->rootPath.$bigimg;
! N7 c" b9 ?, X; E! a - $image->open($srcimg);
/ ^; k4 R$ T% ~6 \ l1 j - $image->thumb(500,500);
) I E/ B; V$ t/ l7 x/ y. r( V5 B: | - $smallimg=$file['savepath']."small_".$file['savename']; J3 e8 Z1 W' B* J+ m& J
- $image->save($upload->rootPath.$smallimg);
- t% f8 [# K5 B - //$_POST['goods_small_img']=$smallimg;" \8 [% x/ t! Z- l" V
-
" A) c5 A0 ~0 \# d8 h - $ S: d2 S% M/ f
-
. l) S1 Q0 M$ u% c - if ($path_old && $img_path) {
7 k. U3 G8 K- P9 f) R& m' _* o8 V& Y - unlink('.' . $path_old);! K! G" t( n2 k8 {5 E Q
- }& ~& |& W3 b5 D% x/ K
-
- H4 \) X1 K/ b- }, w - ' G0 `& l8 ^- P% s
- $res['stats'] = 1;
. s" x! G& ?" f/ x - $res['res'] = $smallimg;
0 X h: `! s6 ]0 K6 i- B% N - $res['name']=$name;7 J! r& f# v& ^2 r: g
- }
/ g9 F! @9 r( G& I/ E8 T( I -
: i6 L- ~ u) |7 F3 f - , S- g [: D( F+ I$ m0 v. f
- }
复制代码 + d* E5 s& X# j+ ^1 g1 e/ K
0 D8 \1 I+ k) Y6 Q |
|