cncml手绘网
标题:
thinkphp 缩略图
[打印本页]
作者:
admin
时间:
2018-7-27 15:27
标题:
thinkphp 缩略图
function imgs_uploads($path_old = null){
4 c& ?. w+ v& H. g& y7 i9 T) q
& Q4 T9 K, Q( n0 l% t q2 ?
$images_path = './Uploads/image/shop/';
8 y) x3 S. i. Q( E9 y
if (!is_dir($images_path)) {
3 ^6 o, k: Z; X: y! y+ o
mkdir($images_path);
2 x7 v: k9 d7 P. T: q
}
8 U) Y; w" o, h5 s/ a
& a `. O6 R6 h9 U. Y
/ h+ f g& h6 {9 A! X
$upload = new \Think\Upload();//实列化上传类
* c0 c" f$ J! F `3 A
$upload->maxSize=4145728;//设置上传文件最大,大小
* S0 ?5 }7 {2 K% d% K. B+ G9 E
$upload->exts= array('jpg','gif','png','jpeg');//后缀
- }& k' p! w1 _* Y
$upload->rootPath =$images_path;//上传目录
) u' ]1 d2 [5 v4 @
$upload->savePath = ''; // 设置附件上传(子)目录
+ c: X' V7 p$ Z: f8 l$ m4 x
//$upload->autoSub = true;
! I9 |6 J q. ]8 W) `
//$upload->subName = array('date','Ymd');
+ {, r; c( m9 X
//$upload->saveName = array('uniqid','');//设置上传文件规则
9 T0 q. P% _+ m+ R% |8 Q7 e0 T
$upload->replace = false;
* L- M: b# ?0 K
$info= $upload->upload();//执行上传方法
7 b/ ]9 v' `2 h9 C) E
if(!$info){
9 S; i/ u; P/ I( y, V& H
$res['status'] = 0;
& r |6 I5 D" u) s \. |# X
$res['res'] = $upload->getError();
# T3 M/ A1 P, X7 k: D* U
* e3 ^/ _" R- Y8 \' A) D
}else {
. Z( Z; H: z4 c5 t6 N" B
0 `, Z, }% L+ n: F& @( B1 @$ l
//获取上传文件信息
k. @, {' s& j
foreach ($info as $file){
' P: N$ v9 ?6 y; f: p% r" _6 ]
$img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
9 ^! ~/ Z4 Y1 J& W
$name[]=$file['key'];
( v1 L; L4 D# ^! [
2 {' J! Y4 w7 a }
) B" ^; Y8 y3 }3 q3 V
}
# j: A- l2 b" V$ f9 z; g
//图片物理目录删除、改名图片用
7 L4 k& U% e9 \2 A6 J$ q5 Z
$bigimg=$file['savepath'].$file['savename'];
9 {2 q% r5 D- G+ ^" a
//$_POST['goods_big_img']=$bigimg;
) }$ g. S' E) P. E: Z
2 M4 ]" z6 | I' ^$ B
7 n: r# n: E- p- L- i
$image=new \Think\Image();
) y+ B$ \' E7 q. \. G; w
8 e: C6 {( D6 P7 b' H2 B I
$srcimg=$upload->rootPath.$bigimg;
" r1 l8 e; ~1 g6 Z" i* G
$image->open($srcimg);
' y3 \( M/ L( L+ o
$image->thumb(500,500);
l# d3 v; C: G- C* M+ X" B
$smallimg=$file['savepath']."small_".$file['savename'];
. O% |& W1 f$ Y1 G1 t( q# t" u
$image->save($upload->rootPath.$smallimg);
4 P W: J' [! A' Q' W" w; G$ T
//$_POST['goods_small_img']=$smallimg;
, U! `5 m, J' k* r
. k% c7 T. `4 I
' `( O. q: s4 k5 S
; A; w. {' K6 A9 a5 ^4 T
if ($path_old && $img_path) {
/ B5 c* K4 H8 P' ~% w# x
unlink('.' . $path_old);
# i2 \' W8 F4 `, T3 N R7 W5 C/ c
}
( w8 u! U' r+ b5 @+ h F( ~
! L0 l" k# s, z6 [, c% E* l
/ h* w. m% w; X2 D( w c# i
$res['stats'] = 1;
: U8 ^/ j1 {3 a+ _( w
$res['res'] = $smallimg;
* A( ~, C3 Q' \3 @! G
$res['name']=$name;
; [" E6 I& W1 C) n) {# [# D
}
8 G, P: w( s0 t' \ h" G
1 B$ h& A' T5 z, D- I
' i5 Y" `& j3 |: L
}
复制代码
' Z; t2 I% o2 G1 M6 w. d7 m
& X+ s" L0 n- j
欢迎光临 cncml手绘网 (http://bbs.cncml.com/)
Powered by Discuz! X3.2