thinkphp 缩略图
function imgs_uploads($path_old = null){$images_path = './Uploads/image/shop/';
if (!is_dir($images_path)) {
mkdir($images_path);
}
$upload = new \Think\Upload();//实列化上传类
$upload->maxSize=4145728;//设置上传文件最大,大小
$upload->exts= array('jpg','gif','png','jpeg');//后缀
$upload->rootPath =$images_path;//上传目录
$upload->savePath = ''; // 设置附件上传(子)目录
//$upload->autoSub = true;
//$upload->subName = array('date','Ymd');
//$upload->saveName = array('uniqid','');//设置上传文件规则
$upload->replace = false;
$info= $upload->upload();//执行上传方法
if(!$info){
$res['status'] = 0;
$res['res'] = $upload->getError();
}else {
//获取上传文件信息
foreach ($info as $file){
$img_path[] = '/Uploads/image/shop/'.$file['savepath'] . $file['savename'];
$name[]=$file['key'];
}
//图片物理目录删除、改名图片用
$bigimg=$file['savepath'].$file['savename'];
//$_POST['goods_big_img']=$bigimg;
$image=new \Think\Image();
$srcimg=$upload->rootPath.$bigimg;
$image->open($srcimg);
$image->thumb(500,500);
$smallimg=$file['savepath']."small_".$file['savename'];
$image->save($upload->rootPath.$smallimg);
//$_POST['goods_small_img']=$smallimg;
if ($path_old && $img_path) {
unlink('.' . $path_old);
}
$res['stats'] = 1;
$res['res'] = $smallimg;
$res['name']=$name;
}
}
页:
[1]