Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Laravel 5 – Upload multiple files to Laravel private storage

Very often you will want 2 things:

  • Upload files not into the public folder, but into a private folder. This is what Laravel storage is for.
  • Upload multiple files at once.

You can achieve it with the following controller code:

  public function add()
        try {

            $file =Input::file('file');
            $extension = $file->getClientOriginalExtension();
            Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
            $entry = new Fileentry();
            $entry->mime = $file->getClientMimeType();
            $entry->original_filename = $file->getClientOriginalName();
            $entry->filename = $file->getFilename() . '.' . $extension;

           //Do redirects, responses, etc.

        }catch(Exception $e) {
                //handle errors

The HTML would be as simple as a normal HTML5 multiple file Upload field, like the following:

 <form action="files/add.php">
  Select images: <input type="file" name="file" multiple>
  <input type="submit">

If you want to use drag and drop uploaders, I’d recommend you can use something like Dropzone.js. But don’t do the enhancements until you have the basic Upload Field working, then you can incrementally make things nicer. You should not need to change much if any controller code to deal use Dropzone.js.


This post first appeared on Ninjamedia Web Development, please read the originial post: here

Share the post

Laravel 5 – Upload multiple files to Laravel private storage


Subscribe to Ninjamedia Web Development

Get updates delivered right to your inbox!

Thank you for your subscription