管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){, @5 y2 J/ H* Y! Q4 R, f
- 6 Q0 K5 R8 e. A: ^3 {
- $images_path = './Uploads/image/shop/';
Y3 k2 K5 [# z. |' W; W - if (!is_dir($images_path)) {. M+ p- w* X- G4 y
- mkdir($images_path);
8 j. a9 a% ]6 S - } - u: @ Y" H8 W* e6 h
- 6 _$ I a( K) G, b
- ( G: c+ `6 S/ @; }! G) ~
- $upload = new \Think\Upload();//实列化上传类' o4 T" F! P8 S U
- $upload->maxSize=4145728;//设置上传文件最大,大小2 r+ G2 B5 F! A# Y. X4 D
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
( Q8 F3 S3 Z! @+ h9 B# Z2 }1 C) v - $upload->rootPath =$images_path;//上传目录# x5 j! }& K( o1 u% u
- $upload->savePath = ''; // 设置附件上传(子)目录. ]: p% B$ V& Q+ R* V' g
- //$upload->autoSub = true;7 H/ X3 {% ~+ O( X9 Z
- //$upload->subName = array('date','Ymd');/ g! k6 a6 H9 |; e. Q! p
- //$upload->saveName = array('uniqid','');//设置上传文件规则# Z3 E9 S, S0 S( g2 s6 N5 D
- $upload->replace = false;/ \2 \/ v! f8 [7 T1 [$ N- V, P1 v
- $info= $upload->upload();//执行上传方法
1 B9 ?& ^8 {& j* e |. J6 J( S" l - if(!$info){. E6 b5 L4 z7 s8 B
- $res['status'] = 0;
; x" P. z. @9 O& M9 ^8 g* H8 j0 | - $res['res'] = $upload->getError();
. A8 ?! B }1 D D7 @5 t# A -
b8 S" e. i _; V8 \ - }else {
+ y' O# W% T$ p6 q9 S - , `) e: V$ z, H
- //获取上传文件信息& j3 Y- `: a) @- V
- foreach ($info as $file){
2 z1 b6 d3 ^* w: p5 z - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];2 f, e/ }* z6 H& p( K' V
- $name[]=$file['key'];
x: V$ b! a9 `: b/ _) |+ ?
: T" t' J2 u* {8 t4 x; @- 0 R" z" Y8 Z+ j1 \
- }+ d# `1 [# {: J5 P
- //图片物理目录删除、改名图片用
6 R" }6 U' t1 G9 H9 j6 ^# l - $bigimg=$file['savepath'].$file['savename'];5 ^+ e% |4 p' l! u3 Q
- //$_POST['goods_big_img']=$bigimg;
) b$ a! d o' [* X" q - " } {1 V. b% S( @
-
& M, _2 t3 Y7 K4 n8 F0 g. m' l/ g3 _( x - $image=new \Think\Image();% X5 Y, q3 X d e9 _2 t
-
% W7 d* b2 Q# S" C4 ]; o - $srcimg=$upload->rootPath.$bigimg;4 L! H' H8 W! Y/ A( R/ O# {; F
- $image->open($srcimg);
* u1 \+ x4 C+ u% V - $image->thumb(500,500);" h( q* t! `8 l; |
- $smallimg=$file['savepath']."small_".$file['savename'];
8 t3 g: T( N- k8 } - $image->save($upload->rootPath.$smallimg);
6 }0 G) y" a+ g# b9 t* G4 ` - //$_POST['goods_small_img']=$smallimg;, v3 X3 ?$ }( A8 y4 F
- 2 c. D' w: ?2 G
- 5 y7 Z; p) N7 T1 i
-
) S, Z8 Z% n! Q. h9 c y( x - if ($path_old && $img_path) {6 Q( @. K9 ?# ?2 A' V2 _
- unlink('.' . $path_old);) H8 h9 s$ S: x9 Y( R/ ^1 P" x
- }- E2 d: ?* V$ F9 L N1 Z
-
& y8 A- U7 _, `9 N+ F, q6 n8 }! ] -
5 Q' X c1 m0 J' J* d9 e - $res['stats'] = 1;3 r! O) ~$ V, @
- $res['res'] = $smallimg;
. r1 S0 T- H) D% G2 | - $res['name']=$name;
- P Q) W. @1 X - }- ]2 E9 U0 L( k) P: i: o
-
. W* a. Y. N5 \ -
) q+ N; ^4 c; m& C* t6 Z! y0 D - }
复制代码 ' V" j* ~; ]7 M- X7 f8 ^9 {
( z, }+ I- ^- L: t# m |
|