管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){; d) N; d3 O' [4 T4 \! U8 P
- ! H% o3 y3 ~/ R% V. a
- $images_path = './Uploads/image/shop/';8 f/ N/ ~; |7 p" n7 i) g' W
- if (!is_dir($images_path)) {8 @& ^. z- r, h" {% {" X z
- mkdir($images_path);
$ ^; X" z5 b# \& z - } 0 _+ E: ]6 b0 \( U
- & n1 g2 A+ a% _6 I/ P
- + J8 C' B, `" ~' c8 _6 M% H
- $upload = new \Think\Upload();//实列化上传类, D2 s6 _( |* ]: u, v+ h
- $upload->maxSize=4145728;//设置上传文件最大,大小
) X1 D$ l/ F# k4 A: S% j& \ - $upload->exts= array('jpg','gif','png','jpeg');//后缀; f% ]2 H6 h ~7 P" ^/ L/ r, e
- $upload->rootPath =$images_path;//上传目录
0 _/ ~9 J% I+ v0 |) P( ` - $upload->savePath = ''; // 设置附件上传(子)目录
4 M+ G8 T1 z; F: a% x q4 B0 I* n7 F - //$upload->autoSub = true;
5 n$ ?3 Y1 L, B" p4 |$ h - //$upload->subName = array('date','Ymd');3 i/ Y1 h- h6 h/ Y7 f, \
- //$upload->saveName = array('uniqid','');//设置上传文件规则5 l" d+ z0 ]4 J6 i" [3 e5 T- g
- $upload->replace = false;1 w- Q+ z8 c4 V4 x& f, U0 n t# `- c
- $info= $upload->upload();//执行上传方法6 U% w" ?( Z% K! A
- if(!$info){8 L# D1 T+ G6 f( S! B
- $res['status'] = 0;; v' i+ w+ I. }, V+ }3 q1 \9 ^# ~
- $res['res'] = $upload->getError();
B6 G' j9 ]* `1 z5 d- t* H+ j -
, R+ t: g% E/ J4 `& ` - }else {
7 q& |& |2 J# Y9 t0 R9 T - 5 F \- u0 W2 a: G# O6 \6 M) x: s
- //获取上传文件信息
7 o5 m5 A. C1 O( z0 G9 j - foreach ($info as $file){" A3 y9 d2 c1 }4 V
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];: \1 s8 {! N! t
- $name[]=$file['key'];$ f$ W+ ?1 B; p: n5 I8 n' `, B
- . Y( Y& H; C$ C" ?, a
- ! ^/ u, z- G* {! r5 j* L) u
- }
- M7 ~7 a' }4 B8 c+ a% ~- ~% U - //图片物理目录删除、改名图片用
- q) a+ L# y/ x4 M0 p( S - $bigimg=$file['savepath'].$file['savename'];
) A4 f2 [/ D9 I. x4 G* w - //$_POST['goods_big_img']=$bigimg;6 |) n5 h2 ?4 q+ H2 E2 B/ f
- . q, u ]- F' r$ U% b
- ) c$ m0 A! j, I( y0 C
- $image=new \Think\Image();
, ]8 D. L+ C( H" F' r - # P2 o0 [7 D' y" `" O. _
- $srcimg=$upload->rootPath.$bigimg;
$ P* }% x! C: s" h - $image->open($srcimg);
? U2 n: H* \- Q& Q& P0 H7 j' O% x - $image->thumb(500,500);
" n5 j3 R, m3 ]7 B3 U! Z# _ - $smallimg=$file['savepath']."small_".$file['savename'];
, O- I, A/ P& \1 ^5 O - $image->save($upload->rootPath.$smallimg);
; C8 Y( j9 N7 r! B5 h1 _& v - //$_POST['goods_small_img']=$smallimg;
" U$ T9 x, m/ X" U. [& y -
+ S/ H) ~/ k) R- p; w
' b2 D$ l, o, Y7 J4 t2 E" W+ C-
! K( v: z# ~. b+ S - if ($path_old && $img_path) {7 u: ]' ^' ~5 I0 h4 F
- unlink('.' . $path_old);+ I2 H' {8 V* B. H2 C
- }
$ a+ Q+ A M2 Q& ]% n/ ^9 O+ L - , W Y* e+ g9 G* o3 n' x
-
8 Q- E, r/ _' G, R# o4 @" z' w - $res['stats'] = 1;. w2 H n" ~% I3 s: C
- $res['res'] = $smallimg;
5 @& _" w% ]/ ~9 ] - $res['name']=$name;
* Y" e5 n, h) j% s. `) e' J# T - }. O. ]; J6 \( s1 v) y- ^
- ! Y& @' _+ Y1 p: P0 r+ y0 z4 ?
- ) k6 Q I5 e( {: q5 K
- }
复制代码 ' R3 ~5 W, ^: Z) H' s2 Y6 ?
2 n& r, N' \" T4 |6 a f" f8 t |
|