管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){6 H3 M1 g0 x; Y8 d. {4 G
-
/ n' m" E: u x3 A8 F - $images_path = './Uploads/image/shop/';5 D, y" {1 C) @" Y% m, {! C
- if (!is_dir($images_path)) {
8 o8 h; N2 A/ J; f+ H# E1 q2 |4 i - mkdir($images_path);6 q& C0 a `8 j# p) T
- } & z: l1 v5 Q$ w. [
-
3 f1 \4 U2 _$ m
& [" M: P" h3 P/ U) X# b- $upload = new \Think\Upload();//实列化上传类
9 }8 o' p. v# Q$ h! C, V - $upload->maxSize=4145728;//设置上传文件最大,大小) Q, ^, o! {7 H6 ^& i, }
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
/ ]& T; A1 ^ J. w - $upload->rootPath =$images_path;//上传目录
9 j/ g$ r2 _0 A- M# S2 G' M* r+ y9 q6 [ - $upload->savePath = ''; // 设置附件上传(子)目录
1 j! m( K/ z; L- @ L4 b - //$upload->autoSub = true;$ S$ W+ i. X" L9 v' v
- //$upload->subName = array('date','Ymd');
/ \$ s8 N$ \1 l; U - //$upload->saveName = array('uniqid','');//设置上传文件规则( p; x8 Q$ C6 C7 e0 P/ h
- $upload->replace = false;2 `3 k2 J6 I# J9 q$ W( L3 T( U% b
- $info= $upload->upload();//执行上传方法% j ^# t* {+ ~
- if(!$info){, J; t5 G2 P, V6 U- s* r1 K
- $res['status'] = 0;
7 B" X) c0 i) | - $res['res'] = $upload->getError();: P' m% L4 v! j4 Q/ h
- 2 v( T* ]6 w$ z8 P4 D% q
- }else {% E0 @# G" e e( |8 O0 f
-
# @" Y0 D4 a3 r. a7 k2 M7 W6 V - //获取上传文件信息6 g P3 C' ^" C. D5 m' L; P" K5 o; k
- foreach ($info as $file){
, M6 Q/ t2 @: F, q5 h - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];0 K* e, O/ `! w/ Y) k! A
- $name[]=$file['key'];
$ ^% ^ U7 Q( n/ E0 x6 V! ?3 A3 X8 u6 |
1 J8 t; ~4 z2 `! o. T3 B- % k4 _3 X0 E8 i
- }
" c+ M5 w/ Z( i5 z1 g( Z/ d4 g3 B - //图片物理目录删除、改名图片用
% H, H+ S# Q) X# |4 n" q - $bigimg=$file['savepath'].$file['savename'];
$ x9 u+ Y8 e! c4 R9 A8 j - //$_POST['goods_big_img']=$bigimg;
/ `0 X3 y0 j1 i -
6 v& T2 {5 Y; {" W$ p( B -
4 D# V$ z1 q4 }) u2 r3 W3 V - $image=new \Think\Image();
U7 E3 {" `. R; c5 N4 l7 [5 Z2 I -
' ], R$ @: e2 W, n6 { - $srcimg=$upload->rootPath.$bigimg;; K" w$ C. i& o n4 `5 n/ d7 ?
- $image->open($srcimg);: k$ Z' R/ A2 x1 o- c% i& _: Y% D. d
- $image->thumb(500,500);
+ k: X( v- d8 M7 L/ Y - $smallimg=$file['savepath']."small_".$file['savename'];: M. ^2 `7 L& w, p
- $image->save($upload->rootPath.$smallimg);
# e. Z9 d5 M ^- N# b! a - //$_POST['goods_small_img']=$smallimg;/ @2 _, Q8 s* z) e
-
2 \% l* f% _ V" o3 L
L$ H; c' u+ X- ! f' u; g" E! T, |2 l+ e
- if ($path_old && $img_path) {0 R( k+ Y$ Q* r! n9 i& q7 M
- unlink('.' . $path_old);
R, w4 C0 i/ z9 E1 E: ^ - }* R$ `/ g1 h& z& a; H
- 0 g8 U/ K! L; w/ k0 Y: ~
-
" I! |$ S' |* F! }$ o/ F4 o - $res['stats'] = 1;
$ I+ p# ?; ?# M+ b# a* _/ M - $res['res'] = $smallimg;
: g5 o: R4 \ e* k - $res['name']=$name;
5 i# r3 }4 ?; [4 x - }
3 n, q6 E- e% L: U -
y5 b, P( `, b5 H - : n/ c: a0 ~2 X$ J
- }
复制代码 ; k I( d- C& f5 ]
; o3 P4 _7 l, ?8 x |
|