管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){8 G" o# U5 O6 w, h9 `
- ) p% `- m8 E" p0 @ Y1 T7 B
- $images_path = './Uploads/image/shop/';
) G5 V @& w/ P3 o( B - if (!is_dir($images_path)) {- F1 ?1 R6 d# |3 Q
- mkdir($images_path);, U5 E1 x. W& ]! W0 [8 _
- } $ R$ T' r7 k/ W, P8 r
-
. c! e' @' Q, v - $ {. K' K! q# g# v8 k. ]
- $upload = new \Think\Upload();//实列化上传类
8 u' @; C' c/ E, ^0 \# { - $upload->maxSize=4145728;//设置上传文件最大,大小
v1 u# K6 N! H' q2 i. ] - $upload->exts= array('jpg','gif','png','jpeg');//后缀
. R1 Q# f! Y3 D6 K - $upload->rootPath =$images_path;//上传目录
5 [6 R& @* |# A3 R9 h& a - $upload->savePath = ''; // 设置附件上传(子)目录
9 P/ s" [+ M: `( k- k! R6 x3 | - //$upload->autoSub = true;
) M* q- L, B l5 ]9 e7 @ - //$upload->subName = array('date','Ymd');
2 ~9 L" y5 |! [) o1 u* r/ o - //$upload->saveName = array('uniqid','');//设置上传文件规则
1 D" G! |6 j9 V' Y. | h1 ]6 q - $upload->replace = false;
) w5 W! H7 u$ a4 q2 ` H3 I - $info= $upload->upload();//执行上传方法" C- w m3 t3 {* r6 R
- if(!$info){
& k* e7 G2 C7 n/ Q - $res['status'] = 0;
( a7 A. G1 c. e. J1 c- j4 A - $res['res'] = $upload->getError();8 S) n. }' f: P7 x+ u
-
5 m- v) Y6 l! m9 {1 z; O - }else {; I J* U" i' T- P2 f% q
- ' j6 e$ d( S3 Q4 `
- //获取上传文件信息
& {* N9 S o7 F - foreach ($info as $file){
' j E! \, G6 N7 |) K7 C* i5 z - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
! d3 d5 A+ g" n8 p/ l8 d" N- L1 c - $name[]=$file['key'];$ @5 i! ^& f7 j
9 B/ `+ B! t( K" e. j4 c! @- 0 z8 U8 @% ^& ?( h$ [, b% B4 v* @
- }
$ f! V" \- N3 C8 D$ q; s - //图片物理目录删除、改名图片用1 ~* R- B, x. u8 h
- $bigimg=$file['savepath'].$file['savename'];. y7 l: w' u- V/ b
- //$_POST['goods_big_img']=$bigimg;2 a+ P% _1 w7 B
- * A7 h; P! \$ F1 H; u
- 6 h( {9 K, _1 I! s0 L' ~% D) s
- $image=new \Think\Image();
( m. A( R5 [ @ -
4 f( }$ `( M" p) U! ~ - $srcimg=$upload->rootPath.$bigimg;
: y1 D5 [: i6 B - $image->open($srcimg);" G8 J _; C- `* \: H
- $image->thumb(500,500);
! @7 A# D6 p. x4 F1 y4 G - $smallimg=$file['savepath']."small_".$file['savename'];
3 W* I& q7 b2 j, W( ^+ n - $image->save($upload->rootPath.$smallimg);( P# G6 [2 W" j {: B
- //$_POST['goods_small_img']=$smallimg;( ?9 ^" m: v4 a, I- u
-
$ ~# x$ j4 T0 w& R
+ d- |# b6 x/ M5 k7 }. n( o- f4 w/ r3 B1 e$ t1 W
- if ($path_old && $img_path) {
' d1 B. u" E4 ^! @% G$ m1 t) p - unlink('.' . $path_old);- T5 T- @/ e3 g
- } B: O& P& ]. f% X7 i! M, W
- , A. V/ B4 w3 E) ?# d% s
-
" c2 G' t8 h, ]5 h2 I* \4 g - $res['stats'] = 1;
& c) z' _" T2 j5 `) L! t' A - $res['res'] = $smallimg;( D K0 r0 e3 i% H& w! b# b% ^
- $res['name']=$name;# _+ }& v% d- R) n3 Y) a1 X: l
- } B, p. l! y7 x8 D1 c3 l& B! V( y
-
, u% J$ w& ?6 V3 s0 T4 A8 j -
6 c; X( N5 O: a$ W - }
复制代码 8 w* L7 i: l8 i: y/ N8 L
r2 y$ U9 L7 z1 W
|
|