管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
4 B# F. c: z7 b: w9 }0 R" f0 F - + E( ?: D8 f/ c& H. |& Z
- $images_path = './Uploads/image/shop/';5 r6 z) j3 D' W4 u) J- y6 ^
- if (!is_dir($images_path)) {
( ~" _- g% }7 @( ~ - mkdir($images_path);
% q. D$ L0 g( ^6 g$ |5 y - }
# ^. c1 I3 }& O& L4 \ -
7 r0 f) j2 p- _& f" N - 3 i' w, y' a* Z" h' k
- $upload = new \Think\Upload();//实列化上传类! J; z% T+ P! n1 Q* u, |: U8 y8 H
- $upload->maxSize=4145728;//设置上传文件最大,大小
6 J1 @. K' F7 ^0 ~4 O0 } - $upload->exts= array('jpg','gif','png','jpeg');//后缀
+ f' b2 S3 |% E - $upload->rootPath =$images_path;//上传目录
/ K$ \% ~) n; `, b: V - $upload->savePath = ''; // 设置附件上传(子)目录" _, }* B( f) O+ ?/ z+ d0 t
- //$upload->autoSub = true;; l W4 T* U, Q4 p% i
- //$upload->subName = array('date','Ymd');
" S9 V, b- O: { - //$upload->saveName = array('uniqid','');//设置上传文件规则
! `! l4 Z! o( X3 } - $upload->replace = false;! S9 ~, @4 r( @" u. r" l% d
- $info= $upload->upload();//执行上传方法5 g% m& t- U( q4 k/ a
- if(!$info){9 v# A/ I1 m6 x% T* ?, b( O8 L: I
- $res['status'] = 0;) ~8 X% q8 M3 m, Y( l; j/ _0 Z
- $res['res'] = $upload->getError();
: _: K; ~. W5 n# V( J6 C3 A - 3 z7 I" x) Z6 q0 M5 q
- }else {
5 s7 h: y" X0 ?( B, z7 g% G -
( S% G, j* t; `3 h$ ?! } - //获取上传文件信息, }- T: Q* }7 C. m
- foreach ($info as $file){9 k- ?4 ~5 h$ P' u0 w0 t# h3 h
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
4 t6 D5 m# w$ W- r - $name[]=$file['key'];- B8 R0 F8 s: A
7 t" N2 G; H( v, S2 b# Z- 7 K5 O8 ?) Q& j J, w( H7 R
- }, F3 U9 M. s3 M# X* z4 ^* R
- //图片物理目录删除、改名图片用3 O( G* j8 z3 y; b
- $bigimg=$file['savepath'].$file['savename'];
$ h( d8 t" [- V; f h x, T - //$_POST['goods_big_img']=$bigimg;1 D( J8 E4 _; {6 L
-
7 J9 f0 w9 b+ v: J: E- l - ' o$ A3 e+ w( b
- $image=new \Think\Image();
- e6 M$ x0 j: v) {. H - . B1 Y) R: c3 f7 ]
- $srcimg=$upload->rootPath.$bigimg;
2 k. P6 \ |6 E5 e4 a" v+ I - $image->open($srcimg);) P- ?* ^7 b+ I+ q% Z0 a
- $image->thumb(500,500);
$ q! W' z! ^% }, i$ y/ O" @- _ - $smallimg=$file['savepath']."small_".$file['savename'];' a1 O; ^2 O! J3 Z3 ]; I, E3 b
- $image->save($upload->rootPath.$smallimg);- O! n" H0 D4 ]4 _
- //$_POST['goods_small_img']=$smallimg;
( N: }6 m0 `. P: M3 x - / @. w& K( Z0 }+ K% u
: e1 Z0 `+ }; N; u, w) q-
* G$ k- V" j. o* G4 l/ N7 X' ] - if ($path_old && $img_path) {
. Z! H/ @) s& h$ \/ F - unlink('.' . $path_old);& L9 b' e5 x7 ?' L6 y
- }0 m- f. T, g( {% h& Y0 S
-
- N2 W$ x, o1 s! [" v - d+ @6 b. F k8 w; Q
- $res['stats'] = 1;4 v ]# p, H1 s: `+ e; K" S
- $res['res'] = $smallimg;
+ O) u6 p+ w7 l3 ]6 @ - $res['name']=$name;
! Y" l5 a& P! c# a, m( _ - }: s4 w2 c& O& B. ~+ T4 V
- 0 f0 ^+ z \" T& b v( z4 k4 q2 R
-
1 u% T$ \7 I7 Q% B - }
复制代码 9 {" X4 U9 y4 V, G7 u
; e: F+ \1 k# Q* \
|
|