thinkphp单个图片文件上传示例,可以在Application/Common/Common/function.php中写入该方法,方便全局调用function uploadAnImg($name){
$upload = new \Think\Upload();
$upload->maxSize= 3145728 ;
$upload->exts= array('jpg', 'gif', 'png', 'jpeg');
$upload->rootPath= './Uploads/';
$upload->savePath= '';
$upload->saveName= array('uniqid','');
$upload->subName= array('date','Ym');
$upload->autoSub= true;
$info = $upload->uploadOne($_FILES[$name]);
if(!$info) {
return '';
}else{
return 'Uploads/'.$info['savepath'].$info['savename'];
}
}
调用方法$url = uploadAnImg('pic');
返回URL示例Uploads/201905/5ccb9975bb461.jpg