如何将徽标保存到公用文件夹中

时间:2019-08-12 07:05:29

标签: laravel

我无法将图像文件保存到公用文件夹

$request->validate([
    'name'=> 'required',
    'email' => 'required',
    'logo' => 'required',

]);

Company::create($request->all());

return redirect()->route('company.dashboard')->with('Success');

3 个答案:

答案 0 :(得分:0)

使用此代码

$image = $request->file('logo');
$path = public_path('/your_folder_name");
$image->move($path,$image->getClientOriginalName());

答案 1 :(得分:0)

通常,您使用命令创建从storage/app/publicpublic/storage的符号链接

php artisan storage:link

这使您能够将文件存储在storage/app/public中并公开访问。您可以使用public_path()助手来获取路径。

答案 2 :(得分:0)

$file = $request->file('logo');

if($file){
  $fileName = time().'.'.$file->getClientOriginalName(); //creating a file name
  $path = public_path('/logo"); //make a folder in public path logo.
  $file->move($path,$fileName);

  $request['logo'] = $fileName; //logo is your database field name
}