cncml手绘网
标题:
thinkphp 缩略图
[打印本页]
作者:
admin
时间:
2018-7-27 15:27
标题:
thinkphp 缩略图
function imgs_uploads($path_old = null){
9 a( N( i6 K4 G! U4 @: p: t' {8 ]8 j9 J
' _6 F) ^5 }/ ~/ d3 l$ J8 t
$images_path = './Uploads/image/shop/';
4 R1 y& _: v u
if (!is_dir($images_path)) {
) {1 L1 u+ a1 V) \* i
mkdir($images_path);
+ O) `+ |2 d) a1 K+ J# L
}
' A3 S4 e# h' B/ j8 D1 A
7 v8 D n7 O1 F3 \& J1 O$ {
" s& P% i+ }- h }
$upload = new \Think\Upload();//实列化上传类
. P! N+ q. ]+ b+ U$ X1 r0 E
$upload->maxSize=4145728;//设置上传文件最大,大小
/ T/ V7 t+ F$ g1 M9 ]* M) A
$upload->exts= array('jpg','gif','png','jpeg');//后缀
; ^6 O$ C* V1 A. ^# p* \
$upload->rootPath =$images_path;//上传目录
( w# Q3 f. G) m/ v a# q! i1 I8 o1 H
$upload->savePath = ''; // 设置附件上传(子)目录
, n, @+ t4 A$ U
//$upload->autoSub = true;
5 Y9 z0 ?& n9 K3 V
//$upload->subName = array('date','Ymd');
. y; x6 q* L! Q$ |, j% w" [
//$upload->saveName = array('uniqid','');//设置上传文件规则
" r3 K `; s- ?
$upload->replace = false;
% e" Q8 x4 I8 I9 b0 R, v0 Q: g
$info= $upload->upload();//执行上传方法
: N/ f! T( Y+ e4 d* y5 i
if(!$info){
& g4 B1 V' [5 i' ]6 A8 F1 w
$res['status'] = 0;
$ l8 |, V( ]% B" q/ I; Z
$res['res'] = $upload->getError();
U0 Q( j( q' D+ e% A
9 a& E& o/ D' g7 O( q
}else {
6 l2 D9 B: ?3 Q: T
( ^+ e/ m( [& R' c& @
//获取上传文件信息
$ K( C& M; {% v9 |1 Y. X* v
foreach ($info as $file){
" }$ w8 i2 \! B
$img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
4 L7 B7 _8 g0 h B
$name[]=$file['key'];
/ O: S# M& [. W
& N1 w6 t5 }9 k- L U
6 e- }8 t B% y/ k
}
! {, h( v2 ^5 L$ \7 c( _% Q
//图片物理目录删除、改名图片用
3 n( i5 S. S6 m6 d+ @8 S/ H! H0 S! Q4 ]
$bigimg=$file['savepath'].$file['savename'];
( k% {4 {0 I) t2 l
//$_POST['goods_big_img']=$bigimg;
2 ^+ l V8 [) {' T b4 O) Y; s
& n& k+ y* }# T) s
4 S4 {. y3 s/ {6 d) M
$image=new \Think\Image();
7 w( `. v4 O1 {3 I
- p: b& ?3 U& J2 y; o2 J
$srcimg=$upload->rootPath.$bigimg;
- E" i L" L. H r0 ]
$image->open($srcimg);
' r( W$ o* ~* @9 y- `/ X
$image->thumb(500,500);
5 p3 ]8 X4 Z; D- O
$smallimg=$file['savepath']."small_".$file['savename'];
E- z, e# V: p; Y
$image->save($upload->rootPath.$smallimg);
. @9 y1 [& _3 V0 V; l2 }/ _
//$_POST['goods_small_img']=$smallimg;
: @% N+ O- ]* Z! M# J3 j
l8 H8 T/ U7 {$ j$ I1 y; |
9 c, `! W G. T! f( ^' y. o
" h% R# H1 h P: \8 L5 S) ?0 Q
if ($path_old && $img_path) {
1 t Y8 G: ^# \: D& S: k
unlink('.' . $path_old);
- b4 c1 X5 J& E) p f* Z% S: Y
}
: E7 z. F; C9 V* Y& k9 a
9 c: D& v) x7 J8 Q5 ~
- C* ]! `; K7 ?: V2 w0 ^& ^
$res['stats'] = 1;
1 Y$ S6 `- x. ?5 p$ l' ?0 c
$res['res'] = $smallimg;
/ n9 h4 z1 ` x& }
$res['name']=$name;
# J" ^3 l* W: `* B, E$ y
}
0 O" Q5 t: E4 g! {
4 a* f- l0 ^8 w! z
. C0 U- f0 f9 ~' K1 y
}
复制代码
% V5 u. {/ ^" k7 x
) Y6 k" N' J0 {+ [* k3 `/ ]! R6 z( \
欢迎光临 cncml手绘网 (http://cncml.com/)
Powered by Discuz! X3.2