管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
1 x8 a, a& I4 s" ]4 b8 w - 9 X" b, ]$ e8 E0 [! M9 X
- $images_path = './Uploads/image/shop/'; {6 G- [5 U$ z( y! L
- if (!is_dir($images_path)) {& t$ g6 g. M, `$ \
- mkdir($images_path);
) H" V: ^0 R& a5 ^4 w - } 8 x2 H" t! L; l& P$ q3 a: ?7 i& |
- . G2 P$ y& d. S; y B! }
- & a% s# a0 l X& p. R
- $upload = new \Think\Upload();//实列化上传类3 @! y( D# B; [; ~8 I
- $upload->maxSize=4145728;//设置上传文件最大,大小
3 j, V& S* Z2 _2 R - $upload->exts= array('jpg','gif','png','jpeg');//后缀
; k: T: A7 C5 c$ M! q& y - $upload->rootPath =$images_path;//上传目录
3 R4 S- j n+ H* o5 R9 i0 i; n( m$ @! ? - $upload->savePath = ''; // 设置附件上传(子)目录) I# m/ O2 K" f1 l
- //$upload->autoSub = true;
8 B0 J2 |" W# M! T. | - //$upload->subName = array('date','Ymd');
! n, M1 ]; b+ P9 q, q( P - //$upload->saveName = array('uniqid','');//设置上传文件规则+ X% \# t5 R, Z8 |1 X! B% s
- $upload->replace = false;
g- _- m$ Y! {) D5 _, d3 ^0 V - $info= $upload->upload();//执行上传方法 @) P# k4 I. M- |9 N" q% u
- if(!$info){9 w# m" {8 @; @2 d
- $res['status'] = 0;
3 [" |3 H2 D8 W- H- g - $res['res'] = $upload->getError();$ I) J3 f, |. U7 i. I
- + T0 J! e, ^% p. n8 t
- }else {0 N4 y6 x; `) L1 U$ F
- 9 _8 s- C! M0 U3 e4 u
- //获取上传文件信息
* j; |& v* C3 f$ y# q- e k! s - foreach ($info as $file){
2 P- _% W+ z& E8 L" |7 G - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
: Q8 n7 s9 U, \9 a; Z9 W - $name[]=$file['key'];
; w8 o/ I7 o9 O. ?0 R2 o$ z
/ |5 d! d4 K2 d& q9 M. f" t-
7 r: @/ z, v d$ Z7 E$ J4 \ - }
5 ]3 U5 T/ e5 b5 h# q - //图片物理目录删除、改名图片用
3 d _2 |! C$ {( _# S8 k - $bigimg=$file['savepath'].$file['savename'];. {& b0 B+ E. E8 j. ~6 W# t
- //$_POST['goods_big_img']=$bigimg;
{, k6 q! O3 n+ Y9 W - / Q4 ?9 g2 `8 R9 _
-
- Y! }# g* y' ~) o8 t( w$ W! D - $image=new \Think\Image();
2 p. M# |2 c3 y! g: s* U - ( P0 N9 r2 q3 S% W! g, p
- $srcimg=$upload->rootPath.$bigimg;7 K4 X7 _) S3 G9 p0 a" ^
- $image->open($srcimg);+ Q) h$ ?* d( c5 W0 d
- $image->thumb(500,500);
8 k5 X$ A/ h; G8 O - $smallimg=$file['savepath']."small_".$file['savename'];
% P: P9 r/ X" |( P5 B- C7 q% u - $image->save($upload->rootPath.$smallimg);
, V- _ A$ O3 i2 r/ { v - //$_POST['goods_small_img']=$smallimg;, @6 k5 |# |. j( d! ?9 a2 a- A3 L& L" C
- . j( y3 b! ] k
- }- b8 c! j6 r1 v' a! z- 5 U) b4 \' V. G1 q5 Y1 K
- if ($path_old && $img_path) {
2 W `4 P, h' Z4 k3 E - unlink('.' . $path_old);
( s7 H. ^8 [7 z2 k - }! Q3 I0 _* T4 l# h& ~2 v; i
-
& S8 L$ S( F: J; S -
# W8 w1 l& X3 ~) V6 p - $res['stats'] = 1;' S& I$ J: y7 ~
- $res['res'] = $smallimg;8 [4 B5 w# T! H, |4 ?
- $res['name']=$name;1 L8 y' [0 r, A0 ]8 s7 n
- }
+ O r- ^, y6 |- n -
+ w: W% Q+ I% D4 J -
@- @9 E8 Y$ l" e2 Z - }
复制代码 # s; l c$ _7 y
5 M. u4 s; z( V |
|