管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
, b: g8 C1 ~3 \" I, \) b' O -
L. Z d& t$ P$ M - $images_path = './Uploads/image/shop/';% @# Y/ @1 o& w4 s
- if (!is_dir($images_path)) {1 i+ O3 z7 Z& t0 @1 m4 L
- mkdir($images_path);
X V- ]$ C' S. g7 i6 H( L - }
8 a( L; s* r; x3 Z# E -
3 i% m/ Q) L" d7 x& y2 B- [6 e h6 I0 c
% N; J9 R# Q" @' ]- $upload = new \Think\Upload();//实列化上传类
5 I {, ]# N9 y" H7 g7 l9 K* e5 y - $upload->maxSize=4145728;//设置上传文件最大,大小2 j+ l6 z+ n4 F" B; V
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
1 u+ A8 u* d v: I0 h - $upload->rootPath =$images_path;//上传目录
1 _3 K" M, {: p% e0 Y) O - $upload->savePath = ''; // 设置附件上传(子)目录, X- ?7 r& a8 b+ _6 [
- //$upload->autoSub = true;4 S+ @$ M( x+ Q$ z3 E# Q
- //$upload->subName = array('date','Ymd');
1 j5 U. n! X8 M# j% r: f - //$upload->saveName = array('uniqid','');//设置上传文件规则
: V% |3 s* S2 \) @2 j5 G+ I - $upload->replace = false;
% s$ B- x' I) F: x - $info= $upload->upload();//执行上传方法' i+ ^/ B7 z/ c
- if(!$info){
6 |& ^5 P# f! D `! E @ - $res['status'] = 0;
* s& W8 y. }! A- C - $res['res'] = $upload->getError();2 Z `- N9 j: x0 N3 e
- % h4 Y; _& F* C' n
- }else {
$ n: b9 A4 D: U( i& L - # k9 Y, b9 Y! } b! x
- //获取上传文件信息
: L |1 @6 G. R: R$ a/ n$ V' x - foreach ($info as $file){
- r* ` N. Y0 t- e - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];$ x0 e/ t; ~" `' } @2 u" l, }
- $name[]=$file['key'];# q) y* m) W6 P
- & z9 j! L/ z+ `
- 7 j% `( w0 G) F% q* h i _: H) e
- }
. Q9 |6 y- |- b' M/ y6 R$ l6 x - //图片物理目录删除、改名图片用2 J" f5 v$ B+ [" @* G
- $bigimg=$file['savepath'].$file['savename'];- ^( [- F/ }: K$ A. W
- //$_POST['goods_big_img']=$bigimg;% X+ k1 M. u$ Z. S6 K2 A+ c
- 7 x. y. d6 l0 `, Z
- 1 f! x) r2 U% Q9 T2 M; Z) l
- $image=new \Think\Image();/ G3 w B' E1 R
- ; K7 Y; E. o' U5 \2 K
- $srcimg=$upload->rootPath.$bigimg;: o, D" ^3 g7 w. U: |# v8 h
- $image->open($srcimg);
6 l* y0 V8 l4 m* G - $image->thumb(500,500);
, x: h( V7 N* T - $smallimg=$file['savepath']."small_".$file['savename'];
+ B" o, n/ Q& ?: Y* D0 U' N - $image->save($upload->rootPath.$smallimg);
/ |. K, q$ ~- _8 s - //$_POST['goods_small_img']=$smallimg;, G+ E% U$ Z# o" t: Z; s9 a
-
: F# G: u1 _) ?0 Y* P- U
) c/ B: [. z6 T0 n" P; {) d-
* d0 D* Y* Q8 J4 A% a, _2 F. g5 s - if ($path_old && $img_path) {( }7 I4 U, \: d/ [
- unlink('.' . $path_old);0 Q5 ~) e2 h5 |/ P: L( k2 G( ?+ k
- }- L# A- e) T, D
- ! X0 c9 u# C& Z) G4 `
- 8 X6 q# h: A F' g% z" }
- $res['stats'] = 1;! H2 H5 a" W( P$ S5 v% g
- $res['res'] = $smallimg;
" f( ]+ g" s, Q& r6 ^- u - $res['name']=$name;8 A/ i) K9 t a# ]$ H% O3 T3 F9 S% ]
- }) V) H" S* V+ I/ @# d" L+ h C
- 9 C, X1 o) q: _: b! X
-
7 ^; \+ y; L/ V - }
复制代码
6 C) [- R% ]' f) z9 I% P, K, s7 X/ Z7 y$ R/ J5 L
|
|