管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
a9 J1 a) p' y1 f* X5 r: b6 L -
: v% w) ^+ Y8 n; i - $images_path = './Uploads/image/shop/';/ d4 [" Y+ s3 I4 f: C' E
- if (!is_dir($images_path)) {* K5 `- `! x% }3 [
- mkdir($images_path);- F' S% p6 m, H, {; x3 _ `- e" {
- } 7 N! J- e2 `9 s& m7 m9 e
-
4 W% T9 m; W4 W" \
! k" o. w/ b& z- B( _) K9 W2 p- $upload = new \Think\Upload();//实列化上传类# ?0 T" c5 u% c6 n' x0 O1 B. a. H
- $upload->maxSize=4145728;//设置上传文件最大,大小: H3 \1 L+ w- r2 }- T
- $upload->exts= array('jpg','gif','png','jpeg');//后缀8 M; O. \, U7 E+ G* d( r
- $upload->rootPath =$images_path;//上传目录
8 m" ?7 a/ D* x9 P& ~6 U - $upload->savePath = ''; // 设置附件上传(子)目录, ]( y& C0 c o# o4 n! |8 T; J
- //$upload->autoSub = true;1 I: l) S. W* r: z
- //$upload->subName = array('date','Ymd');
8 Q1 Y1 E& P, a( r3 j: g# M - //$upload->saveName = array('uniqid','');//设置上传文件规则) D/ d' O4 D. d; ~" E( d7 a
- $upload->replace = false;, p2 j+ g, u6 x* Y1 F) |& ~4 f+ @4 D
- $info= $upload->upload();//执行上传方法7 u1 N2 ]$ [# K5 q7 ]1 U- d
- if(!$info){
; g$ X+ m6 a5 }! C4 `5 x - $res['status'] = 0;
. z# Q$ D4 u8 i# ? - $res['res'] = $upload->getError();
/ p, z% M4 ]0 [* G/ C$ E. s2 a -
+ H5 A6 \" d' D, F+ W; T9 N1 M - }else {
* L& u4 U8 I7 e2 [2 S/ @8 R -
( ~& J( {( f: s# d6 ^5 V) J - //获取上传文件信息/ v- F$ [" R" i' m) K7 ~
- foreach ($info as $file){2 j/ t+ l c% u6 I8 P# f
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];3 Q2 p/ |6 k! l5 d! q2 o- V
- $name[]=$file['key'];$ v- Z* @; M) ]( j
! Z8 V. r1 W$ ~; v+ ]-
n2 E$ `& Q7 ~/ Z - }6 B1 n( M# Y9 }. j4 |
- //图片物理目录删除、改名图片用0 y' ^- p; X6 \2 E* G! O6 y
- $bigimg=$file['savepath'].$file['savename'];4 M `9 T- ^" e7 |6 e+ J0 l( F
- //$_POST['goods_big_img']=$bigimg;
7 b! F, |* l2 \; P -
7 e8 W4 a4 m; s+ S) u- [ - 9 B6 U A7 [9 S6 ~
- $image=new \Think\Image();! k1 V! F2 n' X1 \
-
1 {+ L& c, O2 A* ?/ ^ - $srcimg=$upload->rootPath.$bigimg;
: H9 T; ^" d' j0 ^& Y" _" ? - $image->open($srcimg);
* v5 T% N: f! K3 e v9 ~: R" C - $image->thumb(500,500);. W+ w( h& }; V4 U5 s( w! P
- $smallimg=$file['savepath']."small_".$file['savename'];* C5 J! w/ b7 ~# [1 `
- $image->save($upload->rootPath.$smallimg);
1 \. X( _9 \( V! a - //$_POST['goods_small_img']=$smallimg;5 y& r& n, m0 k5 M6 t9 \
-
9 x2 M& m' ^! F9 [# I( l
, n, J- u! v, R/ j* h5 M-
/ W& ~/ a8 B% r! F - if ($path_old && $img_path) {
; E; b; b1 j6 p9 p4 m( C - unlink('.' . $path_old);. L% E, C% b* J. A
- }! k5 w4 M6 d1 E( ~
-
; ]5 {5 F1 I- B3 v. G2 C& m* \ - ! _# e6 o# d1 C3 ~3 | K
- $res['stats'] = 1;
0 R* r* E3 r; o' x5 Q, H - $res['res'] = $smallimg;
+ Z' G1 ^. Y/ o) e$ M# a; V - $res['name']=$name;6 ]* |3 Q: y: L2 z' F* d V* w' y
- }) g# X0 F" M% y- I
- ) X3 `) }1 i+ P! `! y' t# N3 R
- # }+ @2 M( R' a; o
- }
复制代码
+ U8 S* e6 t* G) ?# o; d
' O" D/ [; B3 f" Y+ X |
|