管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){' Y/ |3 [' x) d4 X3 x! h! k
-
; [2 I) r. `7 {8 ^) d8 r% t - $images_path = './Uploads/image/shop/';' F/ Z$ u& |/ F5 X# P0 h4 J, C1 q; ~
- if (!is_dir($images_path)) {- k8 r( t* T% V$ l. i7 {
- mkdir($images_path);
/ d8 I& F2 Y$ H9 e7 T. D! { - } 0 P" K" L1 p) C8 S+ B+ f/ h, k
-
4 J3 ]# w5 N6 t. h4 z! e: \6 R
; \% N2 z" c y" y- $upload = new \Think\Upload();//实列化上传类% q4 T" t8 Y# p$ A5 F
- $upload->maxSize=4145728;//设置上传文件最大,大小
^" i1 L/ n1 Z5 v! m- S, v1 k' a - $upload->exts= array('jpg','gif','png','jpeg');//后缀1 J" V- K$ x- e* E4 H/ H" r
- $upload->rootPath =$images_path;//上传目录
% h) f7 H* S3 ?8 P, s - $upload->savePath = ''; // 设置附件上传(子)目录
; `+ F0 e6 Q6 w" g - //$upload->autoSub = true;/ I7 t# V1 c! M5 V; [% u6 Y- y
- //$upload->subName = array('date','Ymd');
1 _- V, K) O+ a1 W - //$upload->saveName = array('uniqid','');//设置上传文件规则5 S+ d* P9 U! I
- $upload->replace = false;
: _ ?5 Q0 [7 b6 d1 a7 q - $info= $upload->upload();//执行上传方法% s h! N4 u* S# e7 }/ ^( D7 B
- if(!$info){
& }1 \8 w5 ]5 A5 [ - $res['status'] = 0;
1 l: V! T1 N' W% o - $res['res'] = $upload->getError();+ D( W! q# S; H7 o+ p. B
- . O# y' m! N b
- }else {
1 D9 [: ]; {0 I4 `2 L. n -
1 h( ~5 [6 q' g1 q3 E- V( w% y" W - //获取上传文件信息
5 H2 T4 O$ a( \, }* M' X$ Y - foreach ($info as $file){
) Y8 F( w( b" `/ V, V J - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
$ ?: `7 e |" S% E. A/ P) e - $name[]=$file['key'];
0 e# z. q5 N9 z' S& g# ~ - . Y8 @% A k( \- D
-
8 c9 m6 i" y1 v6 {5 F4 J - }
& S3 a' v* v" d+ Z - //图片物理目录删除、改名图片用
) V a c; L( m - $bigimg=$file['savepath'].$file['savename'];1 k- _$ C9 N6 h' o+ Y$ j& U' M
- //$_POST['goods_big_img']=$bigimg;* ]% d& C: `0 f! c: d
- / ~3 }2 u1 p: m/ O
-
7 d8 j+ g+ s' R) y: a E. y - $image=new \Think\Image();- G! O5 Q/ w% F- [& Z* Y9 x; V, q
- ( m$ i) Y0 d' X+ _' ~* H) e
- $srcimg=$upload->rootPath.$bigimg;: d* k9 [* g3 F5 U4 [! o/ ~
- $image->open($srcimg);" R; u% `8 l0 [: m2 \7 C% k) I5 l
- $image->thumb(500,500);
1 N$ w- {( Z" O7 s - $smallimg=$file['savepath']."small_".$file['savename'];
' g/ R7 x- p7 e% H3 ^6 z, I - $image->save($upload->rootPath.$smallimg); U8 O* v% m1 V( @7 ^3 X/ g7 V
- //$_POST['goods_small_img']=$smallimg;
2 M5 x1 e% `# N0 N - - l2 S5 h, [% a1 z+ m
- 5 e( f9 N$ }% X1 P1 u R; u
-
* J8 z' ~7 y7 {+ Y) a* K - if ($path_old && $img_path) {
! u3 ]& A; m7 u. O - unlink('.' . $path_old);
5 m+ Y4 s) A7 I1 b8 @+ Y' C) Z, a - }
2 O4 Y. H+ P8 n - * D: M3 r( i! i( s# q2 E
-
% w9 ]* ?5 ?/ C6 w& T" g) l - $res['stats'] = 1;
! e% [& f- B; z) {" c2 E0 Q- F - $res['res'] = $smallimg;
9 M+ A0 N4 ^1 O. A5 m - $res['name']=$name;; x7 N. \- Y8 r6 J" u
- }( ?. g; _" ^5 b- N# P3 g# V [
-
7 x; y B5 @! G - 3 k8 h( \$ _# ~4 s4 s
- }
复制代码
: v# N' _4 T4 C2 T, o3 f3 ?( V
6 U( X* g3 `3 i( u# ` S# w8 t+ { |
|