我在laravel 5.4中上传文件的控制器代码:
if ($request->hasFile('input_img')) {
if($request->file('input_img')->isValid()) {
try {
$file = $request->file('input_img');
$name = rand(11111, 99999) . '.' . $file->getClientOriginalExtension();
$request->file('input_img')->move("fotoupload", $name);
} catch (Illuminate\Filesystem\FileNotFoundException $e) {
}
}
}
图像已成功上传,但代码引发了异常:
FileNotFoundException in MimeTypeGuesser.php line 123
该文件在我的代码中有任何错误,或者它是laravel 5.4中的错误,任何人都可以帮我解决问题吗?
我的观点代码:
{{ csrf_field() }}
File input
Example block-level help text here.
submit
解决方法:
试试这个代码.这将解决您的问题.
public function fileUpload(Request $request) {
$this->validate($request, [
'input_img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($request->hasFile('input_img')) {
$image = $request->file('input_img');
$name = time().'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/images');
$image->move($destinationPath, $name);
$this->save();
return back()->with('success','Image Upload successfully');
}
}
标签:laravel-5-4,php
来源: https://codeday.me/bug/20190930/1835476.html