因为公司项目问题,访问量很大,想搭建一个图片服务器,问怎么把现有的保存img方法,修改成提交img后,保存到图片服务器上。
相关代码
private function _uploadImg(){
$img = '';
if(isset($_FILES['img']) && !empty($_FILES['img']['name'])){
$file = request()->file('img');
// 移动到框架应用根目录/public/uploads/ 目录下
$path = config('uploads_path').$this->controller_name.'/';
$info = $file->move(ROOT_PATH.$path);
if($info){
$img = '/uploads/'.$this->controller_name.'/'.str_replace('\\','/',$info->getSaveName());
}else{
// 上传失败获取错误信息
request()->isAjax() ? $this->ajaxReturn(0,$file->getError()) : $this->error($file->getError());
}
}
return $img;
}