Managing uploaded files in Laravel - linking public and repositories

In my Laravel 5.1 application, I store images in storage / app / uploads folder .

My local

disk:

<?php

'disks' => [

    'local' => [
        'driver' => 'local',
        'root'   => storage_path('app/uploads'),
    ],
    // other configuration...

?>

      

The thing is, I can't figure out how to use the image files after loading them, for example. as the source of the tag <img>

. Basically, I need to get a valid image path so it can be used on the page.

For deployment, I am using Envoyer which provides a solution. According to "Intermediary Documents" :

When saving user-uploaded files, you must store them in your application 's storage directory if using Laravel. Then you can use Envoyer's "Manage Linked Folders" function to create a symlinkfrom the shared directory to the repository directory. The Manage Linked Folders button is located on the Deployment Hooks tab of your project.

.. and that's understandable.

But how do I "bind" the store and public folders in my local development environment? Does Laravel provide a way to do this, or do I need to create a symbolic link in my environment manually?

+3


source to share


1 answer


There are several options:



  • Create a controller that will output files

    class AssetController {
      public function show($id) {
        $file = File::findOrFail($id);
        return Response::make(Storage::get($file->storage_key), 200, ['Content-Type' => $file->mime_type]);
      }
    }
    
          

  • Create a symbolic link public / assets => storage / app /

  • Upload files to public / assets instead of storage / app

  • Use overwrite on your webserver to serve files from the storage / application folder . How to do this depends on which web server you are using. For nginx, you can use something like

    rewrite ^/v1/assets/(\d+) /../storage/app/$1;
    
          

+5


source







All Articles