管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
" H* u9 ^$ }1 I/ e1 o+ { - 7 ~. I5 Y7 r- }( U8 Z \
- $images_path = './Uploads/image/shop/';6 L! _/ A- g Y: R
- if (!is_dir($images_path)) {9 @6 ?6 _+ y* J. `. N7 Z
- mkdir($images_path);7 [6 E7 P6 ], @6 [
- }
) l, _ C* c! c. P - 3 B2 a5 D" Y1 M' o
, a6 H9 ]$ |$ S# h0 F) H2 j- $upload = new \Think\Upload();//实列化上传类
+ e& H& ] u+ R7 t! Z% |* l4 s7 t - $upload->maxSize=4145728;//设置上传文件最大,大小$ u8 ]( P% f3 f
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
a* {9 r. y1 K! z$ s$ W t$ C - $upload->rootPath =$images_path;//上传目录
; N1 |3 d. S9 |) ]; n - $upload->savePath = ''; // 设置附件上传(子)目录
* c0 ^5 I# J4 r( L$ n* c/ U1 B) C - //$upload->autoSub = true;
- R, o1 y. f. t: E# ]2 a# ]. [ - //$upload->subName = array('date','Ymd');
4 n9 L$ a6 o m6 \ - //$upload->saveName = array('uniqid','');//设置上传文件规则5 _4 ]/ k9 |! b0 |
- $upload->replace = false;
. v# m+ g4 ~: k1 \: \, t - $info= $upload->upload();//执行上传方法
: W) v6 @; b. ?9 M - if(!$info){
1 v$ f" j" O* \4 j) P - $res['status'] = 0;9 A0 L4 G& X0 g% t; O0 t" \: J
- $res['res'] = $upload->getError();$ R' q6 l2 l& |( B; j; q7 A7 i
-
* I& k6 z5 y& l2 x F5 `6 i - }else {
. C& y' Q5 g, q+ ^ - / {4 g6 C& H0 x2 D3 o& e; O' |
- //获取上传文件信息
/ I6 X1 y# i3 P5 X - foreach ($info as $file){' L: e' Q6 K8 x, T/ U' H% [
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
. k0 V1 S y. T- T6 c* M - $name[]=$file['key'];
* Z1 d& {& Q- C- a9 B
8 ?" ?) ^0 p/ w @! T- % l& E4 e% @! [0 ]* ?3 h
- }
3 ]1 u3 G- B3 z2 E1 e, q( p - //图片物理目录删除、改名图片用; `1 w: @3 N+ y |' z! \
- $bigimg=$file['savepath'].$file['savename'];& n3 P6 [+ Z: G; C7 H& B# O
- //$_POST['goods_big_img']=$bigimg;
6 o4 k6 B& N& l9 u, G: j - # h. Y# N! a/ p$ L! a2 i! l
- ; K A( |" V2 M
- $image=new \Think\Image();+ D& l4 C4 T. J- ~
- 6 z7 T! i- C" z. r( \3 u+ J( R; y
- $srcimg=$upload->rootPath.$bigimg;
9 V k/ f6 v9 \2 ] - $image->open($srcimg);* n1 w& E$ `% L: s5 o
- $image->thumb(500,500); |, D' K% S w$ R* W' a$ A& c3 {
- $smallimg=$file['savepath']."small_".$file['savename'];
6 C# Y7 m, R" U# N9 M8 H( s - $image->save($upload->rootPath.$smallimg);
* N7 F( X: Z e. g4 R - //$_POST['goods_small_img']=$smallimg;1 A3 A/ g [0 W- l% r) }
-
3 Q4 s4 S4 ?! b- u( d' O3 M- H
' O/ D0 F" y7 U- 6 v( g* T4 y8 J! u' p9 v/ x
- if ($path_old && $img_path) {
. E3 s8 q0 ?8 w$ W0 E+ i& d - unlink('.' . $path_old);
$ o6 L& U( L* e+ y - }
8 p+ k& T" G! u0 b- `& c, {3 U - 5 h4 ?5 [$ O O L! Z
-
- s9 l5 e1 g q& V+ M - $res['stats'] = 1;
5 ^% e4 [+ h- \8 `& ]* s' d9 y - $res['res'] = $smallimg;
a' U& ^/ J5 ~- H9 D - $res['name']=$name;
2 B0 Q, F. f- H0 |5 N# Q - }
7 K" |: g4 R3 b) F+ h' o h* C -
+ ^2 _ \: C, }1 U- w2 b0 e -
; K1 u& q. ]0 B9 E. ] P - }
复制代码 _* m: `6 }+ @
' E$ o6 v. w P6 r8 ~5 ~( Q/ n1 U |
|