cncml手绘网
标题:
thinkphp 缩略图
[打印本页]
作者:
admin
时间:
2018-7-27 15:27
标题:
thinkphp 缩略图
function imgs_uploads($path_old = null){
& n4 }# f( O! t2 G
' Y0 _ E. r3 e' N7 n' S* }
$images_path = './Uploads/image/shop/';
! z6 U0 G! X. z5 l6 ?. O1 q
if (!is_dir($images_path)) {
8 U6 d) ~0 d e1 v: u* G7 s W
mkdir($images_path);
. q8 P, R; N$ ?2 H0 x9 o
}
6 S& g0 K, u' Y: s! N
( F3 A5 k, F4 u1 g8 D# Q, G: A4 W" f! y
) M3 G7 [0 N- u
$upload = new \Think\Upload();//实列化上传类
' {! r8 M; G u) i
$upload->maxSize=4145728;//设置上传文件最大,大小
8 I6 d! T8 G2 a* r' o$ j
$upload->exts= array('jpg','gif','png','jpeg');//后缀
~" t; L* D* I" o4 D; U- b
$upload->rootPath =$images_path;//上传目录
v# f3 x4 C |8 l2 |9 s$ G
$upload->savePath = ''; // 设置附件上传(子)目录
: Z+ f0 d" J4 D- j" d
//$upload->autoSub = true;
% _+ }8 m/ T+ U: f5 {' U+ I
//$upload->subName = array('date','Ymd');
. f/ S; o6 s5 u3 e2 e* |7 }- k" ~
//$upload->saveName = array('uniqid','');//设置上传文件规则
* v6 S6 n# }) }
$upload->replace = false;
; d1 q; l- D z; v; M. a6 j
$info= $upload->upload();//执行上传方法
, x2 p" p c6 L) `- |
if(!$info){
) _" x& P& _4 ~
$res['status'] = 0;
1 G+ X/ R$ d! J6 G6 X0 q% P( @
$res['res'] = $upload->getError();
4 q' C1 h% k' f9 o% o
, G. q, }7 N8 i6 p) H
}else {
1 C# X% l h3 i$ |7 q4 h8 r
( w5 B# U7 c/ k4 e
//获取上传文件信息
6 i$ @, _4 N; |5 N! |
foreach ($info as $file){
* y9 m, N; P6 S( s5 `/ `, R- C. F
$img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
& u4 q( l# a* [9 {! }7 F
$name[]=$file['key'];
" e3 M# @. Q+ G/ \9 @% V
3 k n1 A2 O8 ]+ |0 f
! T, u' q9 Y: n
}
8 }4 s" ~% r6 r+ u3 }" z3 R" A( I4 p
//图片物理目录删除、改名图片用
( F; d' V, V* H* Z; j" t
$bigimg=$file['savepath'].$file['savename'];
7 Y/ p B7 u7 I7 D
//$_POST['goods_big_img']=$bigimg;
! E6 U. u6 N1 j4 |
7 F. ]1 G2 O5 x+ \
7 C( r' V* U, j8 t- K
$image=new \Think\Image();
# z, p$ ?3 _- O [! h8 T8 @
1 S. p0 A: h; S6 b6 W, t0 N* [
$srcimg=$upload->rootPath.$bigimg;
. F% r3 f0 ~- |7 L+ q
$image->open($srcimg);
9 K5 Q" Y$ k9 v( y) r! b
$image->thumb(500,500);
# s2 \& Z; Y. ~1 c3 q% b9 c4 Q/ k; j& u
$smallimg=$file['savepath']."small_".$file['savename'];
8 J t, y5 Y- `3 v0 K; n1 n
$image->save($upload->rootPath.$smallimg);
" u) t W$ N+ T. x0 k) N0 ?
//$_POST['goods_small_img']=$smallimg;
8 j/ W9 s$ k; m# E9 N. e4 G$ u
b8 z% C- U! ^ v- I m
) X. L# I: D+ Q9 P0 x- w
$ ]4 B `. S" {0 h5 ^
if ($path_old && $img_path) {
; g! s2 Z- \$ ]! \3 G9 J
unlink('.' . $path_old);
3 H" r2 I& I2 ~" D% m* M7 `
}
5 {. B2 @4 {( S9 i- K) Z: x ]
4 E$ r& x' J( q
0 |2 l0 J1 P8 [8 O$ w6 h
$res['stats'] = 1;
0 }0 y D( o) \) Q* `! @" K% Z9 \
$res['res'] = $smallimg;
0 D- _! E8 L5 N4 p! B7 I. U
$res['name']=$name;
% @8 G2 Y; i& ~& V+ n( X' A
}
, P& f4 o- q( |( K4 ~: O- C' F
+ ^ E* `) a/ k, N' i8 O1 r* b
# ^' E1 i# @( O) i8 A
}
复制代码
7 J1 P) y/ U3 t2 `. c
/ R& P/ @4 D$ f' g+ Q1 _ m2 L
欢迎光临 cncml手绘网 (http://bbs.cncml.com/)
Powered by Discuz! X3.2