管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){0 g2 m0 z, H' r% K2 c; H- H( Z
- . G# X! r7 p- ~& B
- $images_path = './Uploads/image/shop/';" u# Q$ f, H6 n& w2 J: i' N$ `3 o5 u
- if (!is_dir($images_path)) {
. b' o% T5 U* j! x5 U5 i - mkdir($images_path);. E8 d8 l; c" m/ Z8 l
- }
( A: e$ w- {2 I6 [& }) D -
% |+ E" I6 |# e) E& H - ( _6 Z. k2 q( t) a8 o
- $upload = new \Think\Upload();//实列化上传类
9 |8 E+ _7 }& a" d3 b. {& G: i \ - $upload->maxSize=4145728;//设置上传文件最大,大小
- T _& r0 ]& S# P1 \8 `6 m - $upload->exts= array('jpg','gif','png','jpeg');//后缀
5 l4 R( ?# E( ?2 @2 r8 c) R* h - $upload->rootPath =$images_path;//上传目录8 O l9 f( n5 e# C: u
- $upload->savePath = ''; // 设置附件上传(子)目录; i! [; U$ k. W
- //$upload->autoSub = true;
. V* _- I% O+ u3 r* Z( O6 i* k - //$upload->subName = array('date','Ymd');" y: N! w; L/ K9 o& L/ V
- //$upload->saveName = array('uniqid','');//设置上传文件规则' T! F: T, a5 ]8 u2 j: Y( s
- $upload->replace = false;
# F( u6 M6 L& Q2 b! u) F) ~/ ] - $info= $upload->upload();//执行上传方法3 z6 X$ _1 `( V: ^
- if(!$info){# }6 R6 R5 e2 Q5 f p: a- n7 T+ V
- $res['status'] = 0;9 g. w( @' E# ]* A5 g4 Q$ B
- $res['res'] = $upload->getError();8 K- G' ]0 x6 Q1 V' [. P
- $ K W( o' R J2 \$ T# p& ^" @$ x {
- }else {. j; o, Q/ B1 Y8 x
- ' D6 \( o- Q" n$ }5 H# N
- //获取上传文件信息6 L- W9 z+ B; y% a) ?
- foreach ($info as $file){
) u# k e/ g. @* ~7 q) E. D( ^ - $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
& f) P) b6 ?( P! \0 D - $name[]=$file['key'];
. z, U, C- S# j3 z; |9 U2 Q& ] - 0 M% T+ Y9 i. d. @: y/ X
- 0 S& d) v p* _
- }
- B0 o4 O; |* | - //图片物理目录删除、改名图片用# x, X$ Z: B+ V: X+ x
- $bigimg=$file['savepath'].$file['savename'];; g- g2 V8 u5 Y0 b, k
- //$_POST['goods_big_img']=$bigimg;
0 Y! g j: V" U -
% e) j$ L# [/ u8 W - ( G: N$ y, z9 C; o
- $image=new \Think\Image();
) h# R2 i% l K s: h1 u- ] -
( z n6 ~" t% r, K* J2 T- u$ T - $srcimg=$upload->rootPath.$bigimg;+ t9 w' |1 i' R: h
- $image->open($srcimg);
* g, k( c# t* M! r: D" {1 a7 o - $image->thumb(500,500);& H# t, g1 E* m1 t2 g( [! n
- $smallimg=$file['savepath']."small_".$file['savename'];
+ l8 O* T1 M; P% K# K- W& Q1 Z - $image->save($upload->rootPath.$smallimg);
* H- b# H! ~5 i( T. | - //$_POST['goods_small_img']=$smallimg;
2 q3 o' a3 Y/ j2 Q9 h - , j7 v% A6 {& s3 v& ~4 \
- 9 {$ g0 u: \% ?3 X& x, {6 u1 R3 @
-
) Q* B$ K& ?9 w0 f X# r/ C - if ($path_old && $img_path) {
: F1 W3 f2 V2 n8 ?+ u" W ~+ Y - unlink('.' . $path_old);
) A! `( L2 h/ K9 \! F - }
' t7 w/ C# V9 s% k9 g9 S) g - " e" |5 F6 g4 ^0 B6 a, q+ E
- , U9 k* r$ p% L W: b
- $res['stats'] = 1;
8 v5 S* ~$ L, S j% p( A) g - $res['res'] = $smallimg;4 Q% j( Z; ]* {' F1 [
- $res['name']=$name;
; K9 _% c, G' r - }* \( S5 |- b r3 w
- * Y" y4 }1 h, _3 q/ [) c) Z. u" l
-
# P" r9 ]# x T - }
复制代码
0 J/ u! c+ z" D( X3 X% Q4 A3 S, {# W$ f. y3 z
|
|