管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
( \, p; ]! P/ A8 f - % O0 b0 ^; e) H& L4 {- ~! s
- $images_path = './Uploads/image/shop/';- |7 c; b) G# }( o
- if (!is_dir($images_path)) {5 ?" w1 o- B# A2 \) f* W4 F
- mkdir($images_path);: s+ ]; X. P7 o' T p* y4 N% b+ C8 Q
- }
' q! \% k# A: B. Y m1 ] -
* V2 s& \- U2 P0 C4 \5 \% ^ - + d: Y/ B6 d R
- $upload = new \Think\Upload();//实列化上传类
l, x. o2 H7 B: c - $upload->maxSize=4145728;//设置上传文件最大,大小* J3 L( @0 B Q& Q' o
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
- _2 q& \+ X# d) ~: k8 q - $upload->rootPath =$images_path;//上传目录
$ Y' T7 v5 N, b1 ]1 A. P - $upload->savePath = ''; // 设置附件上传(子)目录
4 Q D& g' P9 z- j& g - //$upload->autoSub = true;
- r# \- Y& }. [9 f7 x" h - //$upload->subName = array('date','Ymd');. `( {9 Z2 K6 Y/ W! b& F
- //$upload->saveName = array('uniqid','');//设置上传文件规则
* w% L, y5 O! b/ V* d: V - $upload->replace = false;- A) T2 `6 `4 h; X7 t% Q
- $info= $upload->upload();//执行上传方法
& @5 d9 K' g- c$ [ Z% ~% h - if(!$info){
P% n' ]- B: v+ K - $res['status'] = 0;, W4 j2 z+ |. @3 M, |8 {8 F
- $res['res'] = $upload->getError();( K$ {% V T+ v& a0 ]- [- d7 L
-
+ c+ d/ q/ r8 x* ~# T" r - }else {
) J+ K/ U, k/ |4 [. a2 q - 5 q- T+ f9 W' j* S) V. j
- //获取上传文件信息. N2 l) q+ P9 o/ a$ s
- foreach ($info as $file){3 m' N, ?4 M4 W' e R+ x# W/ o4 Y1 g! {
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
6 m( d7 \- v' m+ | - $name[]=$file['key'];8 w- r+ @) T" b( y7 B
8 R% N5 O3 X7 e4 H-
% Y& A, b$ X/ ?2 A- v1 [ - }
e0 b' G9 P6 {0 \1 x9 k - //图片物理目录删除、改名图片用
8 k9 c1 k; f6 N6 _& s% _; s - $bigimg=$file['savepath'].$file['savename'];& F/ D6 K5 H3 Q
- //$_POST['goods_big_img']=$bigimg;
* ~+ C2 d v# D -
, n; P/ s- d6 } -
j( R: n& Y* R* R - $image=new \Think\Image();% O) _, N9 i3 ]2 [
-
& ~+ T* b7 n% T5 M4 Z2 k% X% s. y - $srcimg=$upload->rootPath.$bigimg;
t' M. b$ `8 N - $image->open($srcimg);
0 N m: s- i' x+ ?/ n6 g1 r - $image->thumb(500,500);
/ t( `) E$ f+ p: K7 u - $smallimg=$file['savepath']."small_".$file['savename'];6 i: i! h' k; P) Q0 Y# K% P
- $image->save($upload->rootPath.$smallimg);% I( W% u( r/ c# H5 c/ O% @
- //$_POST['goods_small_img']=$smallimg;
. J$ e$ ]8 x7 z5 N) G: | -
7 ^; W5 x% t m; O - ( C( Z; F' O6 v- j9 p+ s" o5 r) J
-
2 C: W9 w5 u1 I! h% y$ s0 q - if ($path_old && $img_path) {
* e/ B0 q" n. F0 ?6 N9 l/ M - unlink('.' . $path_old);! p, u& r% e! j. `: x
- }3 |1 E' D% }/ X' ?( Y$ g4 H g. B
-
9 `" L5 i; M8 v& r - " M( J9 C t7 Q" a! k( h2 B- i
- $res['stats'] = 1;
: @/ Z2 R3 Y. x) R* z, C - $res['res'] = $smallimg;
% t8 H2 ~5 H$ G: i& d - $res['name']=$name;
. w% j: z: `4 y. F% M- _ - }& a( ]+ w& H4 u$ `2 u* O" [% e0 m
-
. Q8 b* Y5 i6 Q1 Q2 @ -
2 Y9 a |5 H; w, ^1 } R2 ` - }
复制代码
, ~/ g' Q7 t- x, ]& _5 S ^- x) I& ?" @9 k6 g2 t; E1 c
|
|