管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){ D/ H7 ^! [. S" ~; Q* ]6 y8 l
- 2 b5 ~/ |5 c4 C5 U" w1 n
- $images_path = './Uploads/image/shop/';
' j- Z$ X0 p/ V( p. I/ B - if (!is_dir($images_path)) {
9 t6 R0 R) k4 z, |' s - mkdir($images_path);
3 w* `& C2 `& ?8 x" e - } 8 B$ F, C" p' V
- * [. F+ U' E* `
" }6 Q2 L. i% p2 w" R- $upload = new \Think\Upload();//实列化上传类5 \. \ t2 Y( |6 y; v) W, u2 s
- $upload->maxSize=4145728;//设置上传文件最大,大小! ~+ a; l. I- Y# f2 n' T$ V
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
. b3 b# p5 l) K/ N2 e - $upload->rootPath =$images_path;//上传目录, B3 d/ s/ B- }
- $upload->savePath = ''; // 设置附件上传(子)目录; w$ I6 k- @8 E4 f- M' d
- //$upload->autoSub = true;
4 C9 D# Q" F0 J" t - //$upload->subName = array('date','Ymd');, G4 f: p( M: U/ E5 Q3 \
- //$upload->saveName = array('uniqid','');//设置上传文件规则# O# f ?6 z7 E7 E
- $upload->replace = false;
5 w: W% K+ D2 Q. B7 t. r8 A7 u - $info= $upload->upload();//执行上传方法
# t6 z% f g' G9 S i/ q - if(!$info){
8 L( O: c+ `; s! L5 d% E - $res['status'] = 0;
2 W4 m J$ _) C# E+ Z2 L- i8 N - $res['res'] = $upload->getError();' E6 V% j2 l" f: A5 M
- 2 l D0 a0 o- D4 h# v
- }else {
% I! s7 b$ b: t! v& C8 d - ' u" V$ B: }1 f- U+ j' I6 v
- //获取上传文件信息
4 f4 G# m3 t7 i x" @ - foreach ($info as $file){
! q2 m$ @; T4 D/ j! Y, Y - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
8 x/ Y& J2 P; }9 }9 t1 m: [; { - $name[]=$file['key'];5 q" M1 }: A+ N) n& a; ^0 Z
- ; B& B! s+ b: v$ t' b _
- 1 s: j' M1 x! [. p# P
- }
5 M% K! ?- g( f4 S' t - //图片物理目录删除、改名图片用
/ z% `2 H% O* s1 J: T7 s1 g - $bigimg=$file['savepath'].$file['savename'];* Y4 L5 R& [! b ~) I
- //$_POST['goods_big_img']=$bigimg;
% k+ n4 O8 y* f# T. T6 b" S- u - 9 @+ R# O3 Z( V8 r+ K
- 9 x" u3 k% b2 r+ A/ g) z
- $image=new \Think\Image();
" }! A" L/ q$ l: r! ] -
. j U, Z7 t# t* E5 G& C - $srcimg=$upload->rootPath.$bigimg;- f6 C: x6 O$ v
- $image->open($srcimg);
3 m$ W% q6 p* X6 ^ - $image->thumb(500,500);7 _, h& h% f5 T3 ?
- $smallimg=$file['savepath']."small_".$file['savename'];
4 q- G. F, ~( C, r- ~ - $image->save($upload->rootPath.$smallimg);
; l1 X7 }. V3 g9 k9 Q - //$_POST['goods_small_img']=$smallimg;
2 x) v$ g7 e9 i - / v, g6 S. R, {, D9 Z6 D
# b3 c) T% A! T5 l# e- 7 p( `# C6 Q- I1 I3 I( \4 E/ T2 P, h
- if ($path_old && $img_path) {' N& j2 B. V5 ]( r
- unlink('.' . $path_old);0 T4 q& `8 [( M: W! I+ f3 |6 ~
- }( K; ]" Y E) J7 L) O3 Q3 Y
- ! X: b5 D- D! o) l
- ! h9 `. b; O+ @2 Y+ A
- $res['stats'] = 1;
5 F& ^9 n+ ^" R" V' z! U - $res['res'] = $smallimg;' n+ q* F* c4 J3 ?. h/ ` v
- $res['name']=$name;$ x% Q& T* a+ l o
- }9 p" z' Z7 q' Z
-
$ E& M+ u0 i# a3 }: z# C3 l - ' `) R9 Q5 W0 R5 r
- }
复制代码
2 N% `3 b3 H/ A& d! \4 G1 S6 h) d) g0 M' ]# Y! I
|
|