24

What's the difference between storing files (images) in public/images folder and storing them in storage/app/public?

3 Answers3

33

Public folder means files will be publicly accessible. For example an image stored in public/images/my-image.jpeg can be viewed by anyone by going to

mysite.com/images/my-image.jpeg

However, files stored in storage directory are only available to your app.

Laravel has a php artisan storage:link command that adds a symlink to public from storage/app/public

The reason for this is that your storage may not be your local filesystem, but rather an Amazon S3 bucket or a Rackspace CDN (or anything else)

You will need to setup your filesystem configurations by following the docs https://laravel.com/docs/5.6/filesystem

Once this is done you can get/store files to/from the storage place rather than have everything on your server.

There are 2 helper methods for public and storage to show files:

storage: storage_path('my-file.jpg')

public: asset('my-file.jpg')

H H
  • 2,065
  • 1
  • 24
  • 30
10

The public/images is a webroot directory. This means that it can be accessed via a web browser mozilla, chrome, etc...

The storage/app/public is a folder for cache, logs.

Where to place my files?

Rule of thumb: If you need to control who can view those files put them in storage/app/public otherwise put them in public/images

EDIT

As other answers pointed out the public webroot directory any user can see it. Even non logged users

Bruno Francisco
  • 3,841
  • 4
  • 31
  • 61
2

A similar question was asked here and was answered stating:

public is a "WEBROOT" directory. it consists of files which can be accessed from a browser. There is your index.php file, which take a role of your enter point. Also your css, javascript files there.

storage is a folder for cache, logs etc.

Daniyal Nasir
  • 669
  • 7
  • 22