fastadmin api模块获取前端上传文件处理注意点

 

$suffix = explode('.',$_FILES['hotel_images']['name'])[1];
$newImgName = get_rand_str(32).'.'.$suffix;
$path = './uploads/'.date('Ymd').'/';
if(!file_exists($path)){
mkdir($path,777);
}
$bool = move_uploaded_file($_FILES['hotel_images']['tmp_name'],$path.$newImgName);
if($bool){
$data['hotel_images'] = ltrim($path.$newImgName,'.');
}else{
echo 'error';die;
$this->error('图片上传失败');
}

1。文件名好像必须得用32位随机字符串
2.api模块控制器中保存我没找到如何使用config定义的目录常量,这里直接保存文件的话是保存在public/下,如果想要保存在其他文件,可以使用相对路径。
3.文件名保存在数据库中记得注意保存路径格式,路径不能包含相对目录,所以当你保存文件路径到数据库中,要处理一下。

以上是遇到的几点问题,欢迎指点交流。
上一篇:7 Best Spanish TV Shows to Learn Spanish


下一篇:.Net Core with 微服务 - Ocelot 网关