Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - Difference between storing files in public directory and in storage in Laravel 5.4

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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')


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...