-1
上傳腳本正在工作,文件也被正確/所需的名稱保存。然而,儘管在數據庫中存儲數據,它存儲的.tmp文件名,而不是Laravel在數據庫中存儲tmp文件名
控制器代碼:
public function store(Request $request)
{
$this->validate(request(), [
'title' => 'required',
'body' => 'required',
'featured_image' =>'image|max:1999'
]);
$post = new Post;
if ($request->hasFile('featured_image')) {
$image = $request->file('featured_image');
// dd($image);
$filename = time(). '.' .$image->getClientOriginalExtension();
// dd($filename);
$location = public_path('images/' . $filename);
// dd($location);
Image::make($image)->resize(800, 400)->save($location);
// dd($image);
$post->image = $filename;
// dd($post);
}
auth()->user()->publish(
new Post(request(['title', 'body', 'featured_image']))
);
session()->flash('message', 'your post has now been published');
return redirect('/');
}
它存儲的文件名C:\xampp\tmp\phpD837.tmp
。怎麼了?
你確定它存儲/更新實際'.tmp'文件名?因爲我在這裏看到的是:你不用'$ post-> save()'保存' – cbaconnier
不要懶得複製代碼而不是添加圖片! – teeyo