管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
4 M) @- w" J8 V/ R; Y& L; x -
2 o h& P5 E9 E, y. ]) g6 P; ^ - $images_path = './Uploads/image/shop/';* V( K0 l9 ?5 A* \) r9 D7 F, H
- if (!is_dir($images_path)) {* W. S4 p% ~: g0 S- l3 ?$ @
- mkdir($images_path);
' ~0 F5 b2 C8 c, t8 f7 x& u - } + Y. p* B$ p7 v/ o+ T5 ]" p V: l
- 4 a7 G! ^) {) A5 T0 D* C' P
- " z+ `6 H9 m( }1 [+ s+ V! Q8 e& h$ w
- $upload = new \Think\Upload();//实列化上传类
8 M$ X7 k {$ Z n - $upload->maxSize=4145728;//设置上传文件最大,大小# o4 W, v1 g- k2 Q) i8 x- [7 I
- $upload->exts= array('jpg','gif','png','jpeg');//后缀
6 b( r% q3 i3 Z) J* }6 i - $upload->rootPath =$images_path;//上传目录2 Q! r4 P5 z& m- S0 I
- $upload->savePath = ''; // 设置附件上传(子)目录
/ f |+ X; Z7 J, k, r; V# x7 |( L$ G - //$upload->autoSub = true;
9 a& `* k2 K! T - //$upload->subName = array('date','Ymd');
) n$ C) R" N. d3 v. d5 y& X - //$upload->saveName = array('uniqid','');//设置上传文件规则
. S# V9 I; g0 } - $upload->replace = false;
# }- ]2 F ~% s& S! q - $info= $upload->upload();//执行上传方法
; y" |$ F, l9 U* m4 {0 j - if(!$info){
2 K! x. ~2 u% [ - $res['status'] = 0;7 Z6 v' A0 S" h- x; V
- $res['res'] = $upload->getError();/ \ t! E( E$ M9 A4 I4 `
- ; G1 s. [( ~# i$ A
- }else {
0 d8 i1 W# Y$ Z+ G5 p -
2 S+ f' u# y9 N4 D/ q - //获取上传文件信息: L8 F% v6 l* d2 e' r+ {7 N4 {* \
- foreach ($info as $file){
* `6 {# I; C$ d; s8 P - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
7 Q' M$ a6 C I- {: ]; R7 x - $name[]=$file['key'];
8 [3 A8 H# w2 L, \
- r; u$ A- R5 K- ! ]% w. y5 _ \/ D0 G9 g4 n
- }
7 E$ `) V$ r: @& I$ d3 | - //图片物理目录删除、改名图片用
( m! Z& m: A3 C' z# Y! i, `0 H - $bigimg=$file['savepath'].$file['savename'];
* S4 F- l8 B7 Q- d: l/ W8 l - //$_POST['goods_big_img']=$bigimg;3 f Y$ N" n r, `# u
- / }$ m; c( W! r" {7 K
- % r& d% Y& I8 I% h0 [+ h2 w! x) t0 c" z+ [
- $image=new \Think\Image();
" I6 f2 S5 ^8 Y$ W$ n - : n8 o, k1 G9 e: P
- $srcimg=$upload->rootPath.$bigimg;
y; l/ ^/ {3 |4 k/ D% v7 B - $image->open($srcimg);3 t& _0 i) }* ?2 b7 p, |$ ], K! {# N
- $image->thumb(500,500);
* A" m' z1 K2 h0 y8 g( U4 s% s - $smallimg=$file['savepath']."small_".$file['savename'];+ t8 t4 O3 l5 ]/ i; V- {8 U
- $image->save($upload->rootPath.$smallimg);
( k. W! k z/ g& K# ?9 T" b - //$_POST['goods_small_img']=$smallimg;! |" b" y: P' t' S8 [" n5 L, e
-
& o3 a1 ~9 Q& \* K - $ l7 Z& A% e A: s& q1 ]2 |1 K
-
0 ], `: ^( C1 H1 {" Z7 a# o* {" @ - if ($path_old && $img_path) {1 M, z" I2 C3 d" `3 o: z! t" w1 f
- unlink('.' . $path_old);
" F9 _: g! o1 R% r - }
% M P" R0 y b1 t - 1 b0 W1 j2 \7 G5 q4 p
- 4 t7 b7 ]' V' {. ]7 V- \
- $res['stats'] = 1;/ M+ k* p) ?3 R' z
- $res['res'] = $smallimg;
$ N; q) A' E+ @5 D - $res['name']=$name;
6 \7 a% A; w1 | C5 |7 y - }
5 @# v: K: H7 e' F -
$ ~ o9 s$ d# a; E% O -
; W5 Y6 M- n# o6 \; j: } - }
复制代码 # y, t. s/ ^ c& o) r/ J$ V4 R
+ }! {1 B( \' z: X
|
|