管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){/ S$ \5 \- ~( K
- 2 k/ m% [7 m: q, t9 h6 a
- $images_path = './Uploads/image/shop/';
2 e) r4 t. H& @( _1 o+ _ - if (!is_dir($images_path)) {
3 K; m9 N8 C, G: T - mkdir($images_path);& A+ }2 B& X9 D: ^9 @* K, u2 V
- }
. A- x) e0 j' P i% n y -
/ w+ K' ^7 e( T" @1 G
% l! n! N1 \: b! } k2 R- $upload = new \Think\Upload();//实列化上传类
1 }- r( ?+ {; O( K5 l/ A& ?3 n1 e# C - $upload->maxSize=4145728;//设置上传文件最大,大小
" G8 n6 x* S$ C. P J - $upload->exts= array('jpg','gif','png','jpeg');//后缀
9 _ L" A! S8 [$ |) l C) n+ m$ K* g - $upload->rootPath =$images_path;//上传目录5 q. U2 @" \8 A: m, E* z
- $upload->savePath = ''; // 设置附件上传(子)目录
! u& l) N* K* n; h, m i1 @, T. C - //$upload->autoSub = true; B& m# Q7 A6 }( [1 l2 s3 k
- //$upload->subName = array('date','Ymd');
9 _* S$ z, \* V# R5 N - //$upload->saveName = array('uniqid','');//设置上传文件规则7 H# ?" W2 C. u! N4 H* j
- $upload->replace = false;
4 P; u6 O+ X v$ W3 y - $info= $upload->upload();//执行上传方法
/ z* I# ^4 Z% D; p9 v$ ? - if(!$info){ Y" g, D R) _6 O4 ~, z
- $res['status'] = 0;
- q" m8 P, ~( ` c- z, H; f - $res['res'] = $upload->getError();9 Y+ R( s/ m8 C* @" h" `% y5 u6 b8 P
- # s0 [; z$ H* v4 T: \, K
- }else {. e6 {) [! J5 b! h* F! J* \2 c( \
- & e, O* | E1 l/ A
- //获取上传文件信息
8 U0 Q) b+ P8 I - foreach ($info as $file){
0 j, h9 r: j# ?0 z' m - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
7 |. R( L' m% T+ s$ Q - $name[]=$file['key'];
+ @; y$ T) n. S# P2 J0 C! M/ J
/ h3 w$ G) K/ B8 o/ U& Z- 1 G8 G( ^" @' A: }6 Y# I U4 ~
- }
0 M5 S" v# I5 U2 q0 Z* G l - //图片物理目录删除、改名图片用
, ?% `9 P0 X. }- y - $bigimg=$file['savepath'].$file['savename'];
1 P5 T5 h# J1 ? - //$_POST['goods_big_img']=$bigimg;. y$ g6 Z! [. ]& {/ R
-
( @* C; }$ u; B/ q; b2 Q+ ^1 m -
9 t* k* z" |$ S3 m6 r' Y' X4 V7 L - $image=new \Think\Image();
8 U9 H0 j9 `/ y# N8 ` -
* f. A7 _3 ]- b$ f - $srcimg=$upload->rootPath.$bigimg;5 i) l3 U* A1 D4 U3 R9 k
- $image->open($srcimg);
$ p; `* ~: X: ?% l - $image->thumb(500,500);
8 t: P$ ^7 r ?0 E - $smallimg=$file['savepath']."small_".$file['savename'];
- q. H( r" B$ i7 U$ x" i7 j- C - $image->save($upload->rootPath.$smallimg);6 X2 U" a6 N) g7 A
- //$_POST['goods_small_img']=$smallimg;4 y$ q" h6 F8 i9 R
-
3 x* d0 a. P# F' h7 F' V - . F2 }) R% p, P. z
-
+ R( t( [4 s9 i3 z- ^( F4 a - if ($path_old && $img_path) {- S- N. B: X5 a( M, f1 X: p
- unlink('.' . $path_old);3 N5 T% M* {6 r0 v2 B, l
- }( {9 s( m: ^. D, o3 W Y# f" J
- % u. r. o! `! Z% A
- % n6 \" X9 v- N# B: A! C. T- T2 \
- $res['stats'] = 1;
' `6 I# r6 n+ z7 d - $res['res'] = $smallimg;
0 @" d( r) R3 s9 J& h# L& y - $res['name']=$name;
% ?4 ~' L$ G, `0 H p - }2 E- {4 ?; e. d" D( P& w K
- - I! E7 I7 @" g# u! G2 ]& e6 N5 w
- & x" a. |, r; I+ h) I
- }
复制代码
$ s6 k0 @& r. G; s
9 T6 Y; I ]2 t- ?( ]* b |
|