管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){) `! c. L- i* V/ K9 n
- % g/ L/ b% x4 I. j# E4 ?- B
- $images_path = './Uploads/image/shop/';" Q3 z* Z7 ?6 c2 H4 k
- if (!is_dir($images_path)) {
; K4 E0 x' X- _4 M - mkdir($images_path);
! B6 f1 j6 L H' r; G7 S: @ - }
x x1 R% n, e3 L - - r; G0 ?# q6 k/ Z+ _
- 6 p+ g m, j( }3 F
- $upload = new \Think\Upload();//实列化上传类
1 ^0 I0 M: M: R3 X - $upload->maxSize=4145728;//设置上传文件最大,大小
: B6 B0 E( p( A& y# L; M8 a - $upload->exts= array('jpg','gif','png','jpeg');//后缀
+ Z( h4 E/ Y9 _) R* T J1 o8 p! k - $upload->rootPath =$images_path;//上传目录; W) c6 @: q* c
- $upload->savePath = ''; // 设置附件上传(子)目录' a0 a. q' m" ]7 b3 F
- //$upload->autoSub = true;
+ P8 z9 \9 l- Y! T! o - //$upload->subName = array('date','Ymd');
" C% N, A0 V! ?4 f. a, _3 Z - //$upload->saveName = array('uniqid','');//设置上传文件规则6 c4 g+ d* `! A i2 S% G) W
- $upload->replace = false;! l! n( p; w( X5 j
- $info= $upload->upload();//执行上传方法1 f% q3 h; t; `1 K4 F: V/ x, ~3 T
- if(!$info){
* N9 j3 }4 r) {5 t/ X4 s& b6 [ - $res['status'] = 0;8 r! o' _( D5 _. q& z; i/ l+ d
- $res['res'] = $upload->getError();3 q$ S6 t5 }0 d0 w+ C0 G6 V ~
- " l" G6 U; p" k1 l
- }else {; `1 ]0 X7 f/ L/ ]
-
1 g4 F' y' F, ?7 } - //获取上传文件信息
$ L5 S) D/ ~/ u* j K! c - foreach ($info as $file){
- h! w7 x6 B, A$ M& T - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
j- p, R) G" H - $name[]=$file['key'];/ R9 }8 }' }3 e
- - Y' O7 @& W# o5 d# o o! u% u
-
" J+ b8 L9 z& |9 w' V- ? - }! M/ o9 r0 j3 t/ z' ?
- //图片物理目录删除、改名图片用
0 n& l- a+ e3 C2 o. v, r - $bigimg=$file['savepath'].$file['savename'];% m6 X) e( G% G" J1 j4 ]
- //$_POST['goods_big_img']=$bigimg;3 [4 V! _. i0 U3 E# w+ x- W
- - Z0 b. T$ I" ?4 T5 |2 G" F$ v
- $ P7 Y; F& B+ A; s3 s
- $image=new \Think\Image();8 C ?: j+ ~5 L1 h- h& z& `# w
-
$ M+ L- i+ l& z: u( }$ K - $srcimg=$upload->rootPath.$bigimg;
8 V. ?, {4 S4 I# C& Y2 s - $image->open($srcimg);
: S' V% H+ m- D, E3 X" z# h - $image->thumb(500,500);
6 n) G* P3 K# B" m" a3 }: C, _ - $smallimg=$file['savepath']."small_".$file['savename'];2 s, [/ p9 S/ n3 u4 y
- $image->save($upload->rootPath.$smallimg);' Q, s. z5 R" t& X
- //$_POST['goods_small_img']=$smallimg;
9 B$ c" V: y/ t$ M - * b) \" R7 p1 @: C
- $ H* Z! @9 I3 x8 K4 M: j; U4 o
- ; L r8 Y) g. b( k
- if ($path_old && $img_path) {6 J6 ~1 Q/ t0 `
- unlink('.' . $path_old);1 W/ V- j. q+ ?# f. K! Y, T
- }) c* \: p) [3 R4 d
-
2 E# m( p0 ~4 r2 L -
( I' I: e1 W) Y' b- k - $res['stats'] = 1;
0 S3 P! v- x8 ?' H1 K; `3 I& h* K - $res['res'] = $smallimg; N3 u) I$ R; V
- $res['name']=$name;
7 V" b5 P( W+ U3 v - }- q' i% L7 e- d/ p9 L+ y: F W
-
- I5 Y) @$ x9 e# y P -
5 R, j+ f' g8 E! y6 R - }
复制代码 , g+ S# r2 j1 D! b" a* q e6 Q
' C8 @8 @8 D( R- x5 {6 I |
|