我想将图像文件上传到服务器。而且我无法打开流:“ move_uploaded_file”中的HTTP包装器不支持可写连接”错误 功能。我该如何解决?
$image_src = $_FILES['ex_image']['tmp_name'];
$src = asset('assets/images/excavator/'.$title.'.png');
move_uploaded_file($image_src,$src);
答案 0 :(得分:2)
您需要使用base_path()
方法。此方法返回到项目根目录的标准路径:
if ($request->hasFile('ex_image')) {
$destinationPath = base_path().'/assets/images/excavator/';
$file = $request->ex_image;
$fileName = $file->getClientOriginalName();
$file->move($destinationPath, $fileName);
}
,如果要返回public
目录,请使用:
$destinationPath = public_path().'/assets/images/excavator/';