管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
' }: \" E @( X+ M" J/ c% t -
: a. {& t+ h( R$ A/ y2 D6 X0 S, B - $images_path = './Uploads/image/shop/';
- I1 n. U2 Z1 y% z2 v& S - if (!is_dir($images_path)) {: \) J! F* a; }# f
- mkdir($images_path);
! h; d: A! T" {- {/ C - } / o" }3 J7 \" W9 ?# _3 c: [
- , _. s q0 e9 Y4 D% e$ V
4 b- L- Z) N$ V* [- $upload = new \Think\Upload();//实列化上传类
7 d, S+ x ?0 a, B/ p% s1 p - $upload->maxSize=4145728;//设置上传文件最大,大小3 ?, S$ z, b) G# a
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
# o3 ^" n8 z4 r5 h/ w - $upload->rootPath =$images_path;//上传目录
! h: x7 u0 F1 {7 o! d - $upload->savePath = ''; // 设置附件上传(子)目录
! |1 L @- c8 B, i6 i9 w8 U - //$upload->autoSub = true;
* f8 c4 [4 N/ K% r - //$upload->subName = array('date','Ymd');
+ m8 `% \9 J+ _5 P - //$upload->saveName = array('uniqid','');//设置上传文件规则
9 _1 s- t" I0 N4 A7 X3 k - $upload->replace = false;& |) P$ W) N/ N% o( b8 d
- $info= $upload->upload();//执行上传方法
[+ }& D7 V$ o& N% u - if(!$info){6 B& {" e; s9 M' p3 a, m- g) ~
- $res['status'] = 0;
7 b/ z7 Z5 q. Y, v* ?" Z - $res['res'] = $upload->getError();
3 x" G% \$ m! ~4 G3 U* b* g# t - : H1 I3 n) G% @0 }; F% [
- }else {
0 a* ], ?# m. ~+ U; Z+ v& V& S: t - 4 @- K) ?! q3 V. u% O' ?/ a& q
- //获取上传文件信息4 q3 V. e/ |8 N# l8 _' K7 b
- foreach ($info as $file){, v0 d# U C2 ]/ I1 P7 ]
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
/ Y* m' v5 z$ S - $name[]=$file['key'];; l) {3 |0 d% \+ c( Y
- . w& k- v# x2 B+ W# x
- ) E2 j9 u. ]8 B; G
- }
5 h2 s/ r: G' s" @1 I - //图片物理目录删除、改名图片用
\9 j$ W/ N# k5 C9 o - $bigimg=$file['savepath'].$file['savename'];
4 H* a! \" p' }' L1 N( l4 | - //$_POST['goods_big_img']=$bigimg;' L2 N2 J" }% `, x" s/ X
- " N2 m E/ W& u9 E6 a. n! f
- 7 o/ p% W- ^1 \: Y, ~( }" L
- $image=new \Think\Image();) m3 n' P6 P& {7 I, D" A6 }2 W! j
-
" }+ _( c! U$ Y: K( E6 Q! q; @ - $srcimg=$upload->rootPath.$bigimg;% ~, T# X* l. } }: d7 S
- $image->open($srcimg);! x& L- U* n$ }$ i3 c \
- $image->thumb(500,500);( o# s) Z; `. p
- $smallimg=$file['savepath']."small_".$file['savename'];
: \7 v" \3 S! I5 a) U, j) ] - $image->save($upload->rootPath.$smallimg);
( d6 }- }/ h) D/ S( y ?: \2 w - //$_POST['goods_small_img']=$smallimg;
* G" C% Y6 v) w( g9 R - 4 t" P8 _8 i: l2 q0 B1 D3 ~
' e0 M5 m! D( u! ~1 r-
5 J/ f, B% Q' D" K - if ($path_old && $img_path) {
4 _ ^& t( ^$ }5 i8 [* b V9 n/ @ - unlink('.' . $path_old);2 j+ z% C( m) a9 k) E. o: @
- }2 q8 x7 {) @* ?3 v1 N* O/ U; `
- * H2 n8 v0 r6 |/ N3 C i8 |
- ( y2 O8 r- N& ~- M+ M
- $res['stats'] = 1;
f C) k0 B: M+ j( g4 w- X - $res['res'] = $smallimg;+ j% G/ K9 T7 J" \& v$ S- q
- $res['name']=$name;, K' F% A7 p: w7 `3 H
- }# [9 s6 ]; W/ Y$ E
-
+ h: ~# S6 n4 ]/ J- s H+ ~1 s - 6 I! a" k7 T+ w% k: ?0 D; u
- }
复制代码 b/ a* {* X; E! k, g- ]- O
6 o5 ^# J- d/ d# V3 \1 A' [: H
|
|