管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
+ ~+ a: C N `6 H0 z -
* i( T, @! v6 f0 T/ Y) U8 | - $images_path = './Uploads/image/shop/';+ e* c, j m5 Y7 J
- if (!is_dir($images_path)) {
/ e* `/ d2 Z& w9 o - mkdir($images_path);
( q; r! v$ |- q8 L+ M0 A - }
1 q! `- Y" h* x% d- c: l -
& a5 z* {# E' z) A; a5 a$ Y: ~6 c, l# V - . T7 J! v/ Q! H. E2 h+ j
- $upload = new \Think\Upload();//实列化上传类
$ t3 M) `1 n5 A& T( w4 S - $upload->maxSize=4145728;//设置上传文件最大,大小
( Z* a4 Q9 g1 d, i8 r) j9 M - $upload->exts= array('jpg','gif','png','jpeg');//后缀
5 J* m( S4 l! Y - $upload->rootPath =$images_path;//上传目录; f/ J( U6 ^, F, m! A* D
- $upload->savePath = ''; // 设置附件上传(子)目录( L% }7 P" @; k* @! e* \
- //$upload->autoSub = true;6 |) W& a9 |0 m9 X% g
- //$upload->subName = array('date','Ymd');
" @7 x1 p7 u' w - //$upload->saveName = array('uniqid','');//设置上传文件规则+ J3 O: C% C+ c4 _% v
- $upload->replace = false;
* H5 ? }( E7 M0 G - $info= $upload->upload();//执行上传方法
+ ]/ N* W S9 G* e! N! Y& t - if(!$info){4 [* V9 |5 H7 S1 p
- $res['status'] = 0;" _/ v% I6 O7 e f9 ~: t3 ^: N
- $res['res'] = $upload->getError();+ v2 K- x* B0 ]; x0 t
- 2 K7 c$ a2 l, _. V
- }else {8 K% P: r, E4 ~
- 7 n" ]% K5 ^; c' w6 l. n
- //获取上传文件信息
9 {; V# I( n) s$ u+ j5 h - foreach ($info as $file){
) Y5 o/ `# H1 s3 x+ k - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
% M4 m5 s! h% D6 M- Z5 v - $name[]=$file['key'];
' P7 e% Q: i! U* F5 m
7 e. v0 {" ?' Z K-
+ ^9 ~0 G/ t) H6 c9 K* p+ s% H - }
9 {+ G: U' O$ z8 L- S& F6 Z - //图片物理目录删除、改名图片用
$ A( R5 n* b! [- l% B6 c" V - $bigimg=$file['savepath'].$file['savename'];" G k2 t* g1 K
- //$_POST['goods_big_img']=$bigimg;# o! {) ~/ ^( A2 j1 _2 R$ `% D
-
# Z$ i# R( m2 @$ r' | -
1 e( K- N5 T p3 _7 F/ q& m - $image=new \Think\Image();
/ k- n5 L0 d3 Q; n" Q8 o/ ] - : o: b6 f6 t c6 i5 D
- $srcimg=$upload->rootPath.$bigimg;
: [6 d, W/ ?9 Q0 b) }# T - $image->open($srcimg);
5 }& V, z" I& ~2 c2 l - $image->thumb(500,500);
; `+ B% \5 f7 F# c1 [, r - $smallimg=$file['savepath']."small_".$file['savename'];2 _/ `' o! [: O) K& a5 _+ A
- $image->save($upload->rootPath.$smallimg);
( }0 o* B1 x) ~# H3 c - //$_POST['goods_small_img']=$smallimg;
8 K+ V1 m9 l, d1 {' E2 A - # X8 d+ `& S, B }& w
2 Z- ]- D' n) f* v, x- ' g4 d8 h6 f& u0 ^4 ^# {
- if ($path_old && $img_path) {$ B0 Z- c. a2 C; t
- unlink('.' . $path_old);
2 a4 ]+ M4 A. c8 i3 E. v - }9 l3 S- o9 S- t' _: z. G! G; W$ L- }
-
[% ?! Y' ?) d; `( i2 F* F - 6 }' @5 k) J! g( ]5 c3 v# a
- $res['stats'] = 1;
: J( E- ? F" c$ A" S - $res['res'] = $smallimg;* G1 W) q1 `1 g% q
- $res['name']=$name;
" K9 p% U$ @$ Y) w, D- p' T4 k - }8 w n0 g. |. H1 e% H
- 4 x. A6 Z' S# ?1 p! S" F9 y* o& e
-
7 T! v$ @3 \1 [' l- X* k2 [( \0 l - }
复制代码
5 G* g2 W3 e5 i3 b, x/ w: B. h& |: G" B6 Q" x/ j" g' h
|
|