cncml手绘网
标题:
thinkphp 缩略图
[打印本页]
作者:
admin
时间:
2018-7-27 15:27
标题:
thinkphp 缩略图
function imgs_uploads($path_old = null){
- b9 r8 N; _& F, @
, |0 [# I5 D4 x7 Z9 X6 y
$images_path = './Uploads/image/shop/';
) c u5 F% m3 G/ ~9 a3 r+ Y* V
if (!is_dir($images_path)) {
2 v; v- _; H C) S5 }$ _
mkdir($images_path);
' x9 l9 O) t' p$ z
}
5 {7 L" B/ h a5 P1 C# x$ v2 t
6 l: |" e' R/ O
3 v+ g7 Y8 Q$ E' M4 [" g
$upload = new \Think\Upload();//实列化上传类
) F, y6 ~2 D4 M# R0 J3 w
$upload->maxSize=4145728;//设置上传文件最大,大小
2 }# W7 e; A9 w1 ~8 C
$upload->exts= array('jpg','gif','png','jpeg');//后缀
' p/ ` C! r& K; S
$upload->rootPath =$images_path;//上传目录
, v8 Y' F' g4 ^1 _' Z
$upload->savePath = ''; // 设置附件上传(子)目录
2 d% A( H" d" R$ A5 ~6 Q$ p J
//$upload->autoSub = true;
) _+ }3 q0 g) U; E: O3 ?
//$upload->subName = array('date','Ymd');
8 Y! l2 X w; G7 n: v' _
//$upload->saveName = array('uniqid','');//设置上传文件规则
0 K v' ]9 F6 t' P6 Q
$upload->replace = false;
5 i1 M+ H/ ]7 B
$info= $upload->upload();//执行上传方法
* u) [8 _# j* l8 Z& T
if(!$info){
, S: C# h, ~& g3 a) r; @
$res['status'] = 0;
% t! v9 C9 C X
$res['res'] = $upload->getError();
2 F5 ^& N/ V$ j
/ Z- O5 Q. x r& ]1 y7 ^: |- ^
}else {
6 G0 H1 u! P' [4 Q* c
; u! d) y ~. g+ j" i* _: P$ Q: s+ c
//获取上传文件信息
% E, M2 c9 y! u% c+ n
foreach ($info as $file){
$ {1 a8 M6 b1 m" f3 Y
$img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
& Z, u7 L' [ ]2 z. m
$name[]=$file['key'];
" ~7 G% g* `: Q4 t- v8 n; Q
( B9 n+ }4 y4 N. w0 W/ n
7 F; e& Y& a+ G1 K( T. {" L
}
0 m4 e# q3 x% `4 L: j: A/ J! o
//图片物理目录删除、改名图片用
' V$ o- x+ J: G9 L. x% J. Y
$bigimg=$file['savepath'].$file['savename'];
0 C4 z& u) _+ c$ f$ D( v/ _
//$_POST['goods_big_img']=$bigimg;
8 f; O" g& D4 h+ n6 S+ t
% q1 B; s9 a! x8 ~1 R5 l0 B
4 K, f) y) V2 G/ e, Q
$image=new \Think\Image();
, U$ F- b0 f; }, {) z8 Y/ K
. @0 ^2 s9 T4 ]
$srcimg=$upload->rootPath.$bigimg;
' L) }% J" U" j! ]: a z8 C( \
$image->open($srcimg);
, P0 k5 k1 L# ?
$image->thumb(500,500);
' a* w" c* }/ W1 o9 x# q& W
$smallimg=$file['savepath']."small_".$file['savename'];
% r) [- c9 {+ V9 N
$image->save($upload->rootPath.$smallimg);
2 ?3 i) O7 F$ K( t: {. j
//$_POST['goods_small_img']=$smallimg;
/ Y8 G! p* Z9 ^ n% D8 u
& v3 q+ Q t8 l7 ]9 O
) k* _* f. f; a
3 b9 h( Z& c# L3 n% {3 E" R8 D# F
if ($path_old && $img_path) {
0 K& _/ w( k% I( ]1 l% l; @
unlink('.' . $path_old);
N$ T( H( v. u5 P, |' U
}
9 z3 h0 s0 i# o" x( l
; i. d) K9 ]6 q
& c. p' i) Z. A" [/ s# p! ^
$res['stats'] = 1;
, O) m% X/ ^/ ]* S% f
$res['res'] = $smallimg;
8 G1 J$ i6 z- Y. s8 F- I7 N
$res['name']=$name;
J3 d2 W9 C, H2 w
}
0 V6 Z# e f7 c" ?! y% q
8 o2 y: s, p5 |. F# R1 t
$ ~; Q/ L( S z# ^/ |0 l
}
复制代码
9 \; d1 `: u; m0 {# e* y
, ~: q; }# m# Z* M- _2 _, I
欢迎光临 cncml手绘网 (http://www.cncml.com/)
Powered by Discuz! X3.2