我有这段代码:
public function storeProject(Request $request)
{
$project = new Project();
if ($request->has('slug') || $request->has('position') || $request->has('public')
|| $request->has('pathheader') || $request->has('pathhome'))
{
$project->slug = $request->input('slug');
$namefolder = $project->slug;
$project->position = $request->input('position');
$project->public = $request->input('public');
$file = $request->file('pathheader');
$file2 = $request->file('pathhome');
Storage::put('projects/'.$namefolder, $file);
//\Storage::disk('projects')->put($namefolder, \File::get($file2));
//File::makeDirectory('/assets/img/projects/hola', 0775, true);
$project->save();
return $project;
return $file;
}
}
当使用此函数时,正确创建了/projects/.$namefolder,但文件名是这样的:p5ds31F6iJoZxXypSMlp3z1baKXs5tPAVOaKMGav.png
如何拥有例如:'header.png'? 谢谢!
答案 0 :(得分:0)
使用storeAs()
方法:
$path = $request->photo->storeAs('images', 'filename.jpg');
如果您不想自动生成文件名,可以使用
storeAs
方法,该方法接受路径,文件名和磁盘名称作为参数。
https://laravel.com/docs/5.4/requests#storing-uploaded-files