laraDev98's avatar

Where do you guys put the uploads directory for storing images,pdfs etc in Laravel 5.1?

I've posted a question on stackoverlow http://stackoverflow.com/questions/30831497/getting-notfoundhttpexception-when-accessing-a-image-file-in-uploads-directory-i/30831536#30831536

I fixed the problem but I want to know the best place to put uploads directory in Laravel.What are the pros and cons of putting uploads directory in public folder and outside of public folder?

Which is best practice?Where do you guys put it?

0 likes
11 replies
davorminchorov's avatar
Level 53
  • If you put all uploaded files in the public folder, everyone will be able to see them.
  • If you put them in the resources folder you'll have better control of them and show them when you need to.
4 likes
laraDev98's avatar

@Ruffles

If you put all uploaded files in the public folder, everyone will be able to see them.

I only want admins and superadmin to access this folder.How do I do that?

If you put them in the resources folder you'll have better control of them and show them when you need to.

Laravel docs says that it is for "The resources directory contains your views, raw assets (LESS, SASS, CoffeeScript), and localization files." http://laravel.com/docs/master/structure

davorminchorov's avatar

Ok, present the uploaded files to admins and super admins only using middleware to restrict access based on roles. Maybe there's no mention of uploads because it's better to keep the files somewhere on the cloud/another server and just show them when needed. I forgot about that!

1 like
mstnorris's avatar

@laraDev98 and @Ruffles shouldn't uploads be placed in the storage directory if not in the public directory? I am just thinking in terms of how Envoyer handles things but it makes sense.

Your version specific code lives within the project structure, and your constants (resources, whether that is uploaded etc) live within a storage directory. Anyway, I'm just thinking out loud.

1 like
tucq88's avatar

Hi guys, I used resources directory to save upload file, but I have no idea how to achieve them from root URL ? Could you guys show me away ?

tucq88's avatar

@andreasb thanks for quick reply, but because I'm working with REST so I'd like to get an URL to that file, so client can easily access to it . E.g an image

andreasb's avatar

Hmm well the URL you can very easily generate yourself - and then serve the image you have stored according to the URL either by using some kind of hash or random string <> image stored in a DB.

What I dont know what should happen if the URL is called, meaning how your API works/what should be achieved

jekinney's avatar

As Taylor worked on Spark he had mentioned in a blog post and podcast he is switching things up. Mainly to what @mstnorris mentioned. In the storage/public ? Folder.

Please or to participate in this conversation.