laravel-5web-crawlerfile-security

Secure upload files in Laravel


I have a Laravel 5 project in which I am uploading files in database in Medium Blob format.

But uploading files in database takes some extra time to execute.

Uploading files in database is a secured way to keep files safe from crawlers or some bots.

I have tried to Upload files to the Public folder. But the crawlers can open these files.

Is there any possible way to upload files in the file system?

So that the Crawlers cannot open these files.

I want these files to be Secured


Solution

  • you can upload them outside of the public scope. For example, storage/ folder is a good place. Also, you can grab them using the file system manager. Take a look:

    $image = \Storage::get('file.jpg');
    

    Edit

    A correct laravel installation just allow the content of public/ to be accesible via web browser. If other directories as storage/ or resources/ are public too, then you installation is really incorrect.

    Said that, once you upload the files in storage/ folder nobody can access them except by you using the \Storage facade. When you call for example \Storage::get('file.jpg'); it returns an stream of bits that you can allocate them in a temporary folder and then display it in the webside. Once the request has finished, the image will disappear again from public domain.