管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
/ i1 q$ l0 J3 R) V -
& |2 l7 g" a( F# @ - $images_path = './Uploads/image/shop/';8 S! I6 e* U. G' u
- if (!is_dir($images_path)) {# f4 Z9 C1 I: |9 J" l/ x E
- mkdir($images_path);4 D# Q4 t. y: u+ M+ t! o" W
- }
, ]/ ?! F+ y1 V# x' P9 N9 {, B - 4 _2 K+ S: S5 X, Y
. G5 d6 W8 M" U- $upload = new \Think\Upload();//实列化上传类6 `. s$ F4 j- Q& T# f8 Y
- $upload->maxSize=4145728;//设置上传文件最大,大小+ g& [. ~2 r) n$ s) C! e
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
. H- k: d, {8 f, W( a% g2 e; J6 N - $upload->rootPath =$images_path;//上传目录
C/ }1 @0 h( F) K" b% } - $upload->savePath = ''; // 设置附件上传(子)目录7 K4 @9 O# ^8 S
- //$upload->autoSub = true;
3 w2 C5 s" U7 [ - //$upload->subName = array('date','Ymd');6 {" h1 I- R7 {4 ]1 t
- //$upload->saveName = array('uniqid','');//设置上传文件规则3 ?8 Z6 y2 j+ F2 [: f
- $upload->replace = false;
7 r" n2 q: s( S; D* V6 t. k - $info= $upload->upload();//执行上传方法
: ? T* F& s3 y- |3 `$ L$ l - if(!$info){
6 S6 N7 J6 g; P& g2 N - $res['status'] = 0;
5 L0 t8 L; s6 n5 z+ C& n - $res['res'] = $upload->getError();+ \) R1 `; b) k: G/ u+ |& K
- / Q$ s" V4 Y5 N' `/ v0 e
- }else {8 t* {6 |+ q2 h
- - q; R" C. ]) `
- //获取上传文件信息! x4 q1 d8 r7 ^) v% ?, k1 K
- foreach ($info as $file){
! c9 @2 C( i/ T: t j& L, r( O/ [ - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
1 C+ M% |8 [2 A! U c+ P* w6 D - $name[]=$file['key'];
$ @' E: K9 p7 K0 p2 U - + H z0 w9 C; o7 e7 K
- ) R. [; w J/ _9 V8 f& U+ |
- }
' V) H! t; t3 y5 o - //图片物理目录删除、改名图片用! D' a# m$ ~, M1 O
- $bigimg=$file['savepath'].$file['savename'];
1 U2 u# v# E% J+ ? - //$_POST['goods_big_img']=$bigimg;% S2 m# n2 o$ A" s" O- R3 F% r
- - w5 I2 D3 q9 j4 `
- 9 F" P0 f1 K4 k. a6 v) ]* O" J9 B
- $image=new \Think\Image();7 A7 d- a, G; u* ]
-
" U2 h! H% F5 d6 D. T& ?9 q' \ - $srcimg=$upload->rootPath.$bigimg;) B1 Y* L* v8 ?' A& p _
- $image->open($srcimg);% w! L2 i* H& P, j3 d
- $image->thumb(500,500);4 b$ @! k6 q6 u0 v& b
- $smallimg=$file['savepath']."small_".$file['savename'];
1 R1 y0 T6 W5 M3 m( l - $image->save($upload->rootPath.$smallimg);3 R$ Y& Y, c- b% ^; k4 C
- //$_POST['goods_small_img']=$smallimg;
' S0 I( x z7 H; j - 7 l' B6 T" m ]4 E* K9 T
, d/ w6 m: t; f$ ]- - i$ @2 w5 l) K$ q3 W9 l( {8 _2 k' D
- if ($path_old && $img_path) {
" S5 b5 Y* M5 Y$ y# z& k( N4 W - unlink('.' . $path_old);
$ M+ f9 ?& X! U - }
' ^$ A* ?# L+ }6 h/ W) ^ - : t& X( C, A$ Q" k& e( l+ ^
-
0 I4 W# U- y. K7 h9 \5 @# A - $res['stats'] = 1;
( z4 S' K9 S8 Q; K) Y/ X - $res['res'] = $smallimg;) N) }% e; H8 u9 H
- $res['name']=$name;: _* d. t, b; x; |# x
- }% F7 ]7 _$ t8 a# G
- 2 \3 K) T9 ? H" H' o
- , U8 x* t1 f6 x O7 w
- }
复制代码 ! A P6 H+ b K. I" T; C- @" Z: D
5 N' q. c* W+ p& I |
|