管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
- function imgs_uploads($path_old = null){
# {0 O9 l2 O* D6 R. T - ; a1 K" D' O( S) F
- $images_path = './Uploads/image/shop/';+ P" J, R2 g- j* [% L2 f
- if (!is_dir($images_path)) { y% {! v: N" l1 }/ z4 q& H
- mkdir($images_path);
' x" q1 y/ s& Q. X$ P& }& R8 A - }
8 [) {2 H6 ^/ I. W# q, s - 0 a3 V6 n9 T( \0 F6 y
- ! M% L0 t1 T( f& E/ I3 Y
- $upload = new \Think\Upload();//实列化上传类
2 U$ n% W- q& d) G0 F: O2 X - $upload->maxSize=4145728;//设置上传文件最大,大小- I' j* R2 j7 s8 @# F. |% X( v$ Y
- $upload->exts= array('jpg','gif','png','jpeg');//后缀3 M4 s ~- x0 Y- c
- $upload->rootPath =$images_path;//上传目录" \4 s1 c3 n0 o. N+ Q+ [
- $upload->savePath = ''; // 设置附件上传(子)目录
# B' B- c: u+ G) y - //$upload->autoSub = true;
, i- g8 u. P% Y. ]6 C! i* c - //$upload->subName = array('date','Ymd');$ L7 s$ R4 [ _3 C- i$ c/ O* H
- //$upload->saveName = array('uniqid','');//设置上传文件规则& J7 W6 k4 C; i" [5 C4 Z8 B1 x) j
- $upload->replace = false;, _4 p7 {7 X' B2 \2 B: K
- $info= $upload->upload();//执行上传方法) Q3 J: A. F' C
- if(!$info){
( J. q* N" j8 p# M) b, H - $res['status'] = 0;
6 R( ~5 `( E" k0 ?2 h - $res['res'] = $upload->getError();
: ] c/ d. \7 K% n, U - % [9 G6 u C5 q1 Z$ y
- }else {
- W$ @. M7 \% P -
' S- a( K* A! }" } - //获取上传文件信息- H5 G# h, f8 `1 I* y5 e
- foreach ($info as $file){* I3 o7 r' l9 U4 q9 H
- $img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
4 u+ g1 j2 S7 C$ f3 B' R4 P - $name[]=$file['key'];, ^% N& e( m# V' G* k+ C- v
/ W5 }1 Q- p' w/ |-
; s7 F3 ]8 ]4 ~# u. E) w4 u! i& v8 l - }
! n- a3 u" Q; F9 S$ O9 w6 J - //图片物理目录删除、改名图片用" o- E6 U8 E$ o/ U( u3 B, s
- $bigimg=$file['savepath'].$file['savename'];
/ a z( i7 T8 P0 b7 o9 M - //$_POST['goods_big_img']=$bigimg;
[( ]4 m/ f3 [7 ^0 b" S+ M - 8 Z+ H3 {. P; r9 P
- 6 P3 w) l) V K" D" Z. `
- $image=new \Think\Image();
1 e- N0 X0 W( @8 Z* F& v4 q8 Q - 8 ~6 }- C9 Q) ?( @/ N6 n. I- @
- $srcimg=$upload->rootPath.$bigimg;
1 o8 g5 o E* ~3 Q - $image->open($srcimg);; z- p# K% b2 [" E8 e( n f
- $image->thumb(500,500);
& n, j( M; C; x, u% n - $smallimg=$file['savepath']."small_".$file['savename'];
5 Q# J! Q( a& ~, E7 \ v( h6 E/ a - $image->save($upload->rootPath.$smallimg);, j- B" u% E o7 V, Q: Y
- //$_POST['goods_small_img']=$smallimg;# |4 a' M3 q" \1 n; V3 f0 e; A
- 8 ]$ b) o- S9 G4 w z- V# g! t
- |+ `8 Z! O1 P; [ v; \ a- ) J$ |1 v8 y- U
- if ($path_old && $img_path) {
3 t# ~) r5 S+ ]' q7 b/ ]% @5 K - unlink('.' . $path_old);
5 A( B0 A1 c5 O! ~ - }
9 K( ?, d9 A1 L' s+ F$ r/ f - 7 r2 [6 H6 n* B7 L
-
3 m$ ]' z) t+ i1 Q: w) F - $res['stats'] = 1;! P6 D4 v/ W1 f. o& O! s
- $res['res'] = $smallimg;
q! w4 H, s" K7 P# j - $res['name']=$name;
3 w: \2 `1 _! F! _& A - }5 g8 c2 X) a& O: J1 N" u
-
) M1 A# v! X" P5 t! A - 2 W9 {. u/ }: [" G- c
- }
复制代码 1 A3 @' T4 t! ~1 R& Q( l' M9 B
0 @# ~5 s x# \# v% k
|
|