laravel 文件上传 & 跨域

跨域

框架路由部分,route.php,允许跨域

1
2
3
4
5
Route::group(['prefix' => 'wechat', 'namespace' => 'Wechat'], function() {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: content-type,authorization");
});

文件上传

1
2
3
4
5
6
7
8
#获取上传临时文件
$file=$request->file('img');

#获取文件名
$filename=$file->getClientOriginalName();

#复制文件至存储目录
$path = $request->file('img')->store('/public');