Laravel Uploaded File Not Accesible Through Browser

时间:2019-02-09 09:34:00

标签: laravel upload filesystems

I am using Laravel 5.7, I can upload files to my system with form that I craeted. I am having hard time making them accesible to my users of the system. How do I do that? I keep getting 404 errors.

My filesystem driver

    'default' => env('FILESYSTEM_DRIVER', 'public'),

this saves all files to "storage/app/public",

        foreach ($request->attachments as $attachment) {
            $originalname = $attachment->getClientOriginalName();
            $ext = $attachment->getClientOriginalExtension();
            $formattedname = "doc$doc->id-$i.$ext";
            $filepath = $attachment->storeAs("pdocs/customers/$customer/projects/$projectid/tr", $formattedname);
            ReviewAttachment::create([
                'customer_id' => $customer,
                'project_id' => $projectid,
                'user_id' => $user,
                'filepath' => $filepath,
                'filename' => $originalname,
            ]);
            $i++;
        }

then show the link from that saved attachmed as below;

<a href="{{Storage::disk('public')->url('$attachment->filepath')}}"> View </a> 
  1. How can I access those files through browser?
  2. Can someone clarify the difference between public and local drives option in driver system? They both save the files on my local system --- which one should i be using if I want to show links of uploaded files to the user who uploaded them or people with permission who can view these uploaded file? Public means open to web for everyone or I need to use "public" to make the files avaliable.

0 个答案:

没有答案