控制器
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required',
'body' => 'required',
'cover_image' => 'image|nullable|max:1999'
]);
// Handle File Upload
if($request->hasFile('cover_image')){
// Get filename with the extension
$filenameWithExt = $request->file('cover_image')->getClientOriginalName();
// Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('cover_image')->getClientOriginalExtension();
// Filename to store
$fileNameToStore= $filename.'_'.time().'.'.$extension;
// Upload Image
$path = $request->file('cover_image')->storeAs('public/cover_images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
// Create Post
$post = new Post;
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->user_id = auth()->user()->id;
$post->cover_image = $fileNameToStore;
$post->save();
return redirect('/posts')->with('success', 'Post Created');
我启用了此扩展程序
extension=php_fileinfo.dll
我的laravel 5.5版
当我上传图片时出现此错误
由于没有可用的猜测器,因此无法猜测mime类型(您是否启用了php_fileinfo扩展名?)
我认为图片验证错误
有人对此有想法吗?