管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){3 v' |& a0 U2 O; Q6 A/ U6 X7 ?, K
- : }* T# V- z+ y
- $images_path = './Uploads/image/shop/'; C, l/ C( X- m* a1 t3 M; J
- if (!is_dir($images_path)) {1 ]9 r* [8 X {6 y, ?! M
- mkdir($images_path);( E( ~, R4 Q: {6 P# K& Q
- } 3 L* E4 ?) L8 X' r1 ^8 C; Y
- 0 C* K& c) @0 Z! A; P$ ?7 F! ]
- 9 \: S' ]+ T8 W- t! h" z
- $upload = new \Think\Upload();//实列化上传类
5 C- k5 j& p! E0 o& O - $upload->maxSize=4145728;//设置上传文件最大,大小
' [- l8 K8 m+ v# h - $upload->exts= array('jpg','gif','png','jpeg');//后缀
& J* x) I/ @& u+ E+ k0 m9 G& m" @ - $upload->rootPath =$images_path;//上传目录
; ]6 M4 F' I; ^' v V! @ - $upload->savePath = ''; // 设置附件上传(子)目录- r# B) _1 q" C0 F5 z7 x, s
- //$upload->autoSub = true;8 ~5 @1 o- M" A4 }
- //$upload->subName = array('date','Ymd');% i' T2 k h8 e0 s" d3 Z2 w
- //$upload->saveName = array('uniqid','');//设置上传文件规则# M6 N9 g' [5 a8 n8 \: H! r8 d5 j
- $upload->replace = false;
3 `) D* _$ Q( O8 g/ a! Z - $info= $upload->upload();//执行上传方法0 p) z5 v* _: Q) `
- if(!$info){
1 O) o N X: D( i4 |) Y8 B - $res['status'] = 0;
( i9 Z- z! d% x; F9 ? - $res['res'] = $upload->getError();0 N8 O: C0 a, ?6 i- g# c t
- ' S( W" |4 O, q( ~) E
- }else {7 k' i6 h X+ Q# K+ ]% o
- 6 ?9 l4 M. P( I( D; ?' z
- //获取上传文件信息/ B! k# j5 e+ u3 w
- foreach ($info as $file){
0 f* R7 g/ K' R; j, O$ Q0 w$ X - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
! J# o) }6 ^# x" P/ X9 I - $name[]=$file['key'];: r- ~/ W0 i1 ^) i
4 N0 O. B* k5 Y* [0 r2 M2 N; Y- + R9 s% D3 e. w; Y% I3 i9 i
- }; P& J# ^9 b% r; ]' ^2 X- L. T! n
- //图片物理目录删除、改名图片用% {9 d; s9 c8 ?& s* d
- $bigimg=$file['savepath'].$file['savename'];
. I; N5 S5 I: G0 B - //$_POST['goods_big_img']=$bigimg;9 V7 T& w. N" ~, t; a6 l5 A! d/ ^5 o) T
- : ]& d7 g& ^! x% G7 ~
-
$ R' G9 A: l/ X' g9 j - $image=new \Think\Image();
( t, W: v W1 O4 L# \+ A - ) p3 g2 U" L! }5 ]2 s
- $srcimg=$upload->rootPath.$bigimg;
5 y, T8 x' o. s - $image->open($srcimg);
% [) k- I$ G9 E. Q8 i - $image->thumb(500,500);
% a' ]2 Y# ]1 ?/ p% i9 Z0 q - $smallimg=$file['savepath']."small_".$file['savename'];$ W, e& H) D/ E8 {$ P
- $image->save($upload->rootPath.$smallimg);1 S( c$ e* T; l% v8 @/ P) W K! q* v7 U
- //$_POST['goods_small_img']=$smallimg;8 y+ D7 }# w6 F) N+ q8 o" B
- ; ~) [# V8 Z- N, q/ n; {2 T
; E4 S8 C7 n, U% L- + x0 I: a0 s6 i, k( u" ` |
- if ($path_old && $img_path) {( S: Z% h% u. ^$ y0 J% o4 |
- unlink('.' . $path_old);
, A1 w( U: ?& z) @- ^ - }
' s b$ R8 i3 F3 @1 t0 _ - 9 ~" |; V' r2 Q- O* b0 b9 D. A
-
7 G2 V; a, l( Y# n" M9 a. _ - $res['stats'] = 1;
8 f; J# x/ k; }2 R8 S - $res['res'] = $smallimg;
* ^) ]4 I( m" T' E! I2 W% Q6 Z7 D - $res['name']=$name;' O7 d3 L9 h2 E1 l+ e' l9 g
- }( N$ o4 E+ |: l' m
- ! a6 w; c) q7 b
-
7 o6 |8 B3 z' E/ x0 [$ ^, i - }
复制代码
g* e/ ~! R6 ]) g! s" K# k) K, W" U. @ t4 D# @2 C
|
|