cncml手绘网
标题:
thinkphp 缩略图
[打印本页]
作者:
admin
时间:
2018-7-27 15:27
标题:
thinkphp 缩略图
function imgs_uploads($path_old = null){
: S1 Z% e N# T7 r* Y
; R8 q% O2 Y+ }6 k
$images_path = './Uploads/image/shop/';
$ u( t% a9 I+ g3 M0 R
if (!is_dir($images_path)) {
* |* n' {4 x P
mkdir($images_path);
. C4 m9 z4 G2 @
}
* v Y% p1 A2 V- Q2 G7 _
& G6 Y5 u& P# m! L, j
# w! G5 K3 V: {* H6 \" H
$upload = new \Think\Upload();//实列化上传类
, V( v2 d: N( v; h( M9 \4 q
$upload->maxSize=4145728;//设置上传文件最大,大小
3 i( m' L: Z+ E, \2 s8 X+ Z* m
$upload->exts= array('jpg','gif','png','jpeg');//后缀
& Z: v$ V8 w5 {' y/ Q8 v- n' w
$upload->rootPath =$images_path;//上传目录
) ^9 o3 C" K' l& y& D
$upload->savePath = ''; // 设置附件上传(子)目录
$ K- t& C; [" O q0 ?# k( P1 }
//$upload->autoSub = true;
4 H8 O! y) ?( ~7 M2 C- U
//$upload->subName = array('date','Ymd');
]1 }0 J( P( X) w; {& `$ S
//$upload->saveName = array('uniqid','');//设置上传文件规则
9 K: j4 C4 }7 b$ e' C4 o
$upload->replace = false;
8 Q! N$ e0 ^4 v8 W
$info= $upload->upload();//执行上传方法
3 @9 V% j4 _! D+ G X/ E: d
if(!$info){
) [) F5 B _3 E# ]
$res['status'] = 0;
, b0 ^! [+ B% a, O1 x4 B; |
$res['res'] = $upload->getError();
K. y) @( t1 z5 h& f5 e$ a* S6 W
; K& v# z, f; E
}else {
6 [, `+ f6 e" d4 M( e
' G& T6 {6 d% U' p
//获取上传文件信息
9 j+ ~8 L5 |5 ^
foreach ($info as $file){
9 C% _) G. c+ z% C4 W; q
$img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
9 W* i( c( m0 h6 A4 n4 f- g" \4 @
$name[]=$file['key'];
3 K- w5 x0 h z& T
, x7 W7 r( e0 h5 M" Q$ K- E. o
: O: @0 p" W+ B# d7 o4 l6 e5 P
}
" o) A1 \, w V7 K: t. r9 M
//图片物理目录删除、改名图片用
% a' r+ Z U9 t! |
$bigimg=$file['savepath'].$file['savename'];
0 h( u M+ b/ v1 D! O9 C- A
//$_POST['goods_big_img']=$bigimg;
% C: v2 E) ?0 L8 k9 v o
: t4 \( S6 J! E$ \5 k
) Q8 S. u! t! S' x
$image=new \Think\Image();
" G4 t* p# o3 D' D( o2 `
X' M0 \$ F- U* L3 z) a. {
$srcimg=$upload->rootPath.$bigimg;
1 B; U ~+ O ~3 v9 Z7 D# c1 ?9 q* Y
$image->open($srcimg);
9 m- E. d/ i. p3 V9 e7 D! s
$image->thumb(500,500);
. t8 u/ W2 ]0 h! d- {* D& o
$smallimg=$file['savepath']."small_".$file['savename'];
1 c1 n { w. p/ E; l- Y
$image->save($upload->rootPath.$smallimg);
4 Y! C$ c1 E6 B; x) A4 w4 v; c7 K
//$_POST['goods_small_img']=$smallimg;
) s- I/ P% G" |
, Z, F% r- w' T' l% `( R' k: |
! B' u" e' w. m/ w4 |% P' h
/ Y% f! u* t6 ^. P( w) `# t& z5 C
if ($path_old && $img_path) {
) t" g- \; p! |
unlink('.' . $path_old);
- O1 D7 C7 M- J. k
}
+ k- \# x% s5 S9 r1 P" J
) Z8 L6 G7 |. j2 }+ L6 h- x* r
2 V* V* R: V7 b1 L5 \1 a: U
$res['stats'] = 1;
( L8 [4 @3 U: t7 h J9 D
$res['res'] = $smallimg;
9 W, N; s9 o3 L' r- W/ n% H
$res['name']=$name;
4 w9 a+ X9 {, q/ _7 X4 U7 @
}
$ t- ]8 Z* Q+ r, q! O
1 Q% ]3 ^$ @. }% i4 a6 B
9 Z8 g+ m1 {+ V1 U- X
}
复制代码
3 A- _. T9 N7 y
- i" Y* Z. R) g* D% V. S: j0 o
欢迎光临 cncml手绘网 (http://www.cncml.com/)
Powered by Discuz! X3.2