管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
; z$ m, Y4 p" S0 I- ] -
0 |$ u1 B5 y" T" U4 B; s - $images_path = './Uploads/image/shop/';1 f) X$ F6 R N' \- I" @+ J
- if (!is_dir($images_path)) {
9 m1 ~% ^$ l, a" u) |1 R5 _ - mkdir($images_path);% g, r& t+ ^0 v! K! u: m! F
- } ( v8 v* G8 O! N4 h
- ' v% h- z B* s* I) i
- 1 J* A: u& O) R1 S
- $upload = new \Think\Upload();//实列化上传类4 ^, K. P, ^& F3 A! j0 d
- $upload->maxSize=4145728;//设置上传文件最大,大小
, A# R. q& R! t* @5 P( R2 } - $upload->exts= array('jpg','gif','png','jpeg');//后缀7 c9 n4 @1 m! ?: L& ]/ g$ n
- $upload->rootPath =$images_path;//上传目录: R# B& k6 C% [" g9 q. ]
- $upload->savePath = ''; // 设置附件上传(子)目录
* b' {" ` i; Y6 k q) K3 M7 D( A1 } - //$upload->autoSub = true;
# J4 B$ X" ]( X - //$upload->subName = array('date','Ymd');
; i$ c: p" |9 N! C: P5 _( Q5 p( S - //$upload->saveName = array('uniqid','');//设置上传文件规则
1 m& |& i# E' D* x - $upload->replace = false;
" u9 r- r/ W$ |2 X2 E - $info= $upload->upload();//执行上传方法
3 w+ D- g: W0 Q& V - if(!$info){
, ~) s9 h* p0 z1 F* R& B3 h - $res['status'] = 0;
5 M5 V$ m* S( O5 v - $res['res'] = $upload->getError();
+ D0 J6 ~0 p4 \# l% C -
$ X( q- H. t! z, p% @# A$ Z - }else {& `: s. a- J! J g- J% I# x
-
! @% m9 W; U- |% U5 c - //获取上传文件信息. M8 ~$ X( ~! j" P! V4 w
- foreach ($info as $file){2 ]7 m/ A: b5 R8 T5 q1 u8 S# f8 g/ g
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];# K `. V$ T" h2 }2 W% x
- $name[]=$file['key'];
- Y. ], h6 w" w+ N8 s$ c - 2 }/ U6 Q, p0 c3 W; `) E/ A1 t
- ) F: t( A% p' O! X# Y
- }
# g/ n* Y# v H& c0 e! Y! j! W9 [0 k% { - //图片物理目录删除、改名图片用
! V g+ @1 e5 J4 Y' { - $bigimg=$file['savepath'].$file['savename'];
6 u: B( g3 D+ f+ { - //$_POST['goods_big_img']=$bigimg;
3 K) l5 M6 y9 P& x0 t -
$ f2 ^7 j" F' S1 J8 d - 0 |5 T/ {& t+ i# `- x6 _; Z% c& b4 C
- $image=new \Think\Image();
2 V. w6 @3 K! D, D( X4 | -
0 V- d; _ z. y2 N" [ - $srcimg=$upload->rootPath.$bigimg;! e& H1 d6 I7 i% \2 R
- $image->open($srcimg);
& y& r) {2 V) M+ T - $image->thumb(500,500);
& U `4 j! Y: G - $smallimg=$file['savepath']."small_".$file['savename'];
- Y4 `) J7 M( e/ O& f - $image->save($upload->rootPath.$smallimg);( q+ G8 V) H2 j: p W
- //$_POST['goods_small_img']=$smallimg;! w" ~$ _- {7 t6 a. V3 l
- O/ y( I: ~2 f/ `5 g5 U. M
- ' w+ T; U, g) Z$ ?7 U- Y
- 4 ^( v f9 @2 R9 M
- if ($path_old && $img_path) {
1 e8 h1 w4 O7 G9 q: S - unlink('.' . $path_old);- U0 p6 Y7 H; C n" @. S7 A% E
- } a; x2 E% v8 p8 M" Y! s4 t
-
! ^8 S2 g% a" J" v -
8 u4 d5 C% h- H) g - $res['stats'] = 1;
J R! Z6 A l! n4 u6 y" a - $res['res'] = $smallimg;
0 X: ^, n& h$ Z+ V - $res['name']=$name;
" r' C$ F% L" @2 J - }8 C, e; M$ t @% S
-
1 q! b- Q6 ?! [$ F+ n - . |) s. S% D& _& A( M
- }
复制代码 ) c7 v2 w' g6 ?0 A# }
/ M2 y0 `6 Q/ B r' J D! j' ^! m |
|