管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
! i1 z5 T* x' J" E/ h0 u -
8 \5 B8 a! O# x% {. m2 S - $images_path = './Uploads/image/shop/';
/ D: h+ ^# @8 ^$ `/ a* i - if (!is_dir($images_path)) {9 }+ \. w) O. p7 K% c
- mkdir($images_path);7 z6 U5 T! Q3 }2 k/ X
- } " a* {$ A. [0 W& s4 L
- $ s9 ^; J1 [; w9 m
- , M( l$ w( ^8 V6 t7 j4 X
- $upload = new \Think\Upload();//实列化上传类- Y* ~* q$ I- _6 o
- $upload->maxSize=4145728;//设置上传文件最大,大小
8 J& J* d" Z+ y% ^ - $upload->exts= array('jpg','gif','png','jpeg');//后缀6 m0 J- K4 L( \9 p" |$ J; E
- $upload->rootPath =$images_path;//上传目录
8 v/ [6 S3 |: ~* r9 [ - $upload->savePath = ''; // 设置附件上传(子)目录
8 o0 {5 r- a: Q6 H- _ t' w - //$upload->autoSub = true;
2 f+ X: \0 o. B( B1 n% W - //$upload->subName = array('date','Ymd');
! F. R1 y9 J% a; s" D) A - //$upload->saveName = array('uniqid','');//设置上传文件规则
# I- i: `& S2 g6 C7 |7 ? - $upload->replace = false;, E' a9 P8 i9 J( J' o
- $info= $upload->upload();//执行上传方法! a& ^1 S' o/ s4 H4 Y, ~( V2 f% z+ c- a
- if(!$info){% E/ Q# h& h( e
- $res['status'] = 0;
/ W7 z+ Q5 {2 E# ]+ { - $res['res'] = $upload->getError();
$ D" D ^7 d: V J2 R2 X7 `. B -
; S- i; x2 w; E& Y' C - }else {
- d6 x) ^- h+ S - % n: R/ u- r O }3 P2 ?) V( ]
- //获取上传文件信息
/ s. y, I5 K& p; L - foreach ($info as $file){+ T7 A* r8 q) w! j9 z0 H
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
, t7 }2 z; }2 i; ^( E - $name[]=$file['key'];
2 l' F# S2 R# C
3 l* _0 b* ?' P1 s2 }6 B* q-
6 c& U* H m6 K7 M' D3 \ - }
& W. [. J# K9 b& O4 h( ?$ I9 K( z: E - //图片物理目录删除、改名图片用9 v- G( s4 f! f1 N* S
- $bigimg=$file['savepath'].$file['savename'];
7 U" W1 Z" [% B0 _: [ - //$_POST['goods_big_img']=$bigimg;, J% f3 \. x& u* b2 X3 d5 k
-
) a5 [; G w6 x$ j6 O, O# b -
8 ~: F$ |* {- m5 ~$ ^; |& Y - $image=new \Think\Image();9 ^. v, L! Y8 p% j) P4 v3 }
- 9 Z1 c* B- t6 h7 V6 K
- $srcimg=$upload->rootPath.$bigimg;8 m8 g/ } p. K! j$ B! O0 r
- $image->open($srcimg);9 j" A5 _; ^5 ]' {5 {
- $image->thumb(500,500);8 P+ Z0 O `2 C* n
- $smallimg=$file['savepath']."small_".$file['savename'];: y* G0 m" G& c2 b8 T
- $image->save($upload->rootPath.$smallimg);
9 ?. @! u3 I7 z/ |. \ - //$_POST['goods_small_img']=$smallimg;1 Q1 k; w1 U& n, p6 Y( L& d2 |9 n
- 7 Z7 h5 {7 T( a% m% c6 K7 U% r
$ o& y! P' l. V4 w% w. S- a-
8 b' R0 U; x3 w, m1 ~: L, w3 A - if ($path_old && $img_path) {
' n* u2 G7 y# L9 |& w1 B( V" ^ - unlink('.' . $path_old);5 `# Q9 O$ n& M+ l5 c
- }
+ Z7 I3 P& i( z$ b - % s; {4 J2 U( H0 D0 w& u& U
-
- | O4 `$ G8 l" i - $res['stats'] = 1;8 Q, I2 U$ I6 C0 X' f ~+ ~
- $res['res'] = $smallimg;2 u6 q7 `2 J3 o9 E2 A, P- F2 N. s
- $res['name']=$name; X. H2 T8 U$ u; L. H
- }' U8 p- t/ _" W9 Q. W2 _
-
* ?. z& w# t( d -
4 k& G3 s$ q- G8 V - }
复制代码
/ J6 ~2 q% \' A4 p! E6 o% w7 b- e3 M. V" A
|
|