将图像存储到公用文件夹

时间:2018-05-24 06:32:55

标签: laravel laravel-5.5

你好团队帮助我我想将图片上传到“my-Project_folder / public /”但现在上传到“my-Project_folder / storage / app /”这里是我的config / filesystem

  'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ], 

和我的控制器

 {
        $filename = $image->getClientOriginalName();

        if ($request->hasFile('image'))
        {
            $request->file('image')->storeAs('images', $filename);
        }

        $creator = new Content_form([
            'media_id' => $request->get('media_name'),
            'content_title' => $request->get('content_title'),
            'content_description' => $request->get('content_description'),
            'date_occured' =>\Carbon\Carbon::now()->format('Y-m-d'),
            'page_number' => $request->get('page_number'),
            'image' => $filename,
        ]);
        $creator->save();

2 个答案:

答案 0 :(得分:0)

您通过以下方式存储在Laravel的默认存储路径中:

$request->file('image')->storeAs('images', $filename);

您必须指定存储路径或磁盘:

Storage::disk('public') -> put('image.jpg',$request->file('image'));

答案 1 :(得分:0)

   if ($request->hasFile('image')){
      $file = $request->file('image');
     $extension = $file->getClientOriginalExtension(); // you can also use file name
     $fileName = time().'.'.$extension;
     $path = public_path().'/yourfolder';
     $uplaod = $file->move($path,$fileName);
     return $fileName;
   }