管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){& ^! o. `% \! ^2 q* x) A2 P1 C2 ^% {
-
7 ?/ N0 C$ r0 Y: l/ b) @0 G - $images_path = './Uploads/image/shop/';7 f* l0 X7 v8 x9 [' w! k
- if (!is_dir($images_path)) {
$ i: E8 U) _- \& F1 @3 O - mkdir($images_path);5 O$ a5 {8 \( C. u
- }
7 Q( p: W, o5 T( u% p( W - * L" i- Z+ @0 a7 Z
- 0 g3 P% h$ Z" K8 w! o
- $upload = new \Think\Upload();//实列化上传类0 t% s' w1 ]1 H6 _
- $upload->maxSize=4145728;//设置上传文件最大,大小& J+ y6 F6 y9 f5 e; n
- $upload->exts= array('jpg','gif','png','jpeg');//后缀) ]. k& U2 k- c% R4 K- |8 f' f. u
- $upload->rootPath =$images_path;//上传目录, _' X6 L, D8 Q" q/ H) g
- $upload->savePath = ''; // 设置附件上传(子)目录
. h- n) t) s0 l - //$upload->autoSub = true;
9 x( g B3 f1 O2 o; K - //$upload->subName = array('date','Ymd');
% i4 x( h& {3 x2 \3 U! \ - //$upload->saveName = array('uniqid','');//设置上传文件规则
2 z& `2 H6 T' u - $upload->replace = false;
) A1 T# M8 V, D2 n. F j - $info= $upload->upload();//执行上传方法! Q6 J( v; \8 q
- if(!$info){. }) W" g. }1 _! K
- $res['status'] = 0;8 B+ [$ M/ l/ B1 @
- $res['res'] = $upload->getError();
, B! g4 q7 a& ]2 [ - 4 Q( E$ k5 G6 i3 B; q% O
- }else {
7 l( @$ L0 I, n3 g* Q, H -
/ `$ `1 h: H' ] - //获取上传文件信息
& e% l3 [: V: b: }* z4 |. y& b - foreach ($info as $file){. V- g+ m2 G" C4 U [
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];) x% X+ m# _2 k9 X/ C$ T7 P5 r
- $name[]=$file['key'];
/ p! v4 |$ x) W% p
( [- Y6 \* X1 D" m" z- G-
, W; ~5 l* j4 @9 A - }
- M+ s1 G2 x% `% S7 b - //图片物理目录删除、改名图片用
) M) j4 E+ D/ V7 D0 s1 }1 x& D( A. \ - $bigimg=$file['savepath'].$file['savename'];
) J2 c: h; p& @+ J - //$_POST['goods_big_img']=$bigimg;- n1 u0 D; R3 ^# H3 p
-
3 ]8 q% p, R( P( {+ l y% m* N - 4 \+ K# E, y8 a- |: `; [
- $image=new \Think\Image();
3 [& R& H4 c: ?0 M+ h% J -
6 }5 M7 t/ i, }* Z. T% e/ W9 D - $srcimg=$upload->rootPath.$bigimg;
, M( J, m2 ]2 J' i2 S7 Q9 ]' T - $image->open($srcimg);( H1 l% }, O' h, Z0 [ ?$ t
- $image->thumb(500,500);
# t, x- ^. U' _; i" N/ W6 B+ k - $smallimg=$file['savepath']."small_".$file['savename'];
: N2 ^& t# U. q- k4 ~ - $image->save($upload->rootPath.$smallimg);
# P" \9 E* H0 W+ S& V2 @ - //$_POST['goods_small_img']=$smallimg;) ^- G( d" j) X% z' \
- 9 j" M2 b( w' C9 X# r; {$ ~+ m
- 3 x+ K( w5 K) a( O) K {5 n
- ! ?% S5 U: E: D
- if ($path_old && $img_path) {
! u3 a8 J" a* A0 M9 y) R$ e2 X - unlink('.' . $path_old);
& C% l( i5 \' i6 v - }, X% }2 @- K6 B x
-
$ i4 W; O: E8 ]2 I - 4 [+ P5 g. B( G1 Z- R3 n# Z4 a
- $res['stats'] = 1;( L9 o+ x l& {% D
- $res['res'] = $smallimg;4 v* r8 Q# i2 F6 t% ]7 K( s
- $res['name']=$name;- e8 |# a0 {$ R8 q
- }3 r( e& D' b# A; R
- ; j& S4 k1 v/ s# n6 j) i7 m
- + k: O, ?3 `4 M `' Z( C" U0 C- D
- }
复制代码 " A8 z8 @) h! G. b0 n4 V! H3 M
" T8 G3 ~, {3 x; \7 P& W k |
|