我想问一下,如何让某人选择一张图片,然后点击上传,图片就会保存到我的项目中(例如:project / public / images)。谢谢:))
答案 0 :(得分:2)
你可以这样做:
$file = $request->file('image');
$name = $file->getClientOriginalName();
$path = public_path("images/$name");
Storage::put($path, File::get($file->getRealPath()));
然而。我建议使用laravel medialibrary包:
https://docs.spatie.be/laravel-medialibrary/v4/introduction
这样你就可以:
$post->addMediaFromRequest('image')->toCollection('images');
答案 1 :(得分:0)
否则你可以这样做
$destinationPath = '';
$filename = '';
if (Input::hasFile('file')) {
$file = Input::file('file');
$destinationPath = public_path().'/images/';
$filename = time() . '_' . $file->getClientOriginalName();
$filename = str_replace(' ','_',$filename);
$uploadSuccess = $file->move($destinationPath, $filename);
}