当前位置:网站首页>ThinkPHP upload image compression size

ThinkPHP upload image compression size

2022-06-25 12:26:00 sr_ www

function layuiUpload($path = '') {
    
	$upload = new \Think\Upload();
	$upload->maxSize = 2097152;
	$upload->exts = ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx'];
	$savePath = $path ? './upload/' . $path . '/' : './upload/';
	$upload->rootPath = $savePath;
	$upload->autoSub = false;
	$res = $upload->upload();
	if (\stristr($res['file']['type'], 'image')) {
     //  If the uploaded image is compressed 
		$image = new \Think\Image();
		$image->open($savePath . $res['file']['savename']);
		$image->thumb(800, 800)->save($savePath . $res['file']['savename']);
	}
	$this->ajaxReturn([
		'code' => 0,
		'msg' => '',
		'data' => [
			'fullSrc' => 'http://' . \currentDomain() . \str_replace('./', '/', $savePath) . $res['file']['savename'],
			'src' => \str_replace('./', '/', $savePath) . $res['file']['savename'],
			'fileName' => $res['file']['savename'],
		],
	]);
}
原网站

版权声明
本文为[sr_ www]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200532457118.html

随机推荐