在 Laravel 中在哪里上传产品图片?
Where to upload product images in Laravel?
我正在使用 Laravel 框架构建电子商务应用程序。哪个位置最适合在前端上传产品图片、滑块图片、横幅图片和所有动态上传的图片?
storage/app/public
public/img
如果我要去 storage/app/public 位置。我怎样才能将这些图像访问到网站前端?
非常感谢您提供的任何帮助。
使用
public/img
然后在前端用asset函数定位
{{ asset('name_of_file') }}
将图像存储在 storage
目录中。
这是最好的地方,因为您可以使用 Storage
门面,这样可以轻松存储图像。 https://laravel.com/docs/5.6/filesystem
如果您要将存储目的地更改为 CDN(例如 Amazon S3),您也可以像在本地一样使用 Storage
门面。您只需要更改 config/filesystems.php
中的配置,存储图像的代码将保持不变。
一旦你将图像存储在存储目录中,你就可以使用 php artisan storage:link
https://laravel.com/docs/5.6/filesystem#configuration
通过符号链接将它们暴露给前端
这将创建一个从您的存储目录到 public 目录的符号链接。
您可以使用助手 asset
来检索图像的路径。 https://laravel.com/docs/5.6/helpers#method-asset
--
关于如何在存储目录中存储文件的例子有很多:
https://quickadminpanel.com/blog/file-upload-in-laravel-the-ultimate-guide/
https://scotch.io/tutorials/understanding-and-working-with-files-in-laravel
我正在使用 Laravel 框架构建电子商务应用程序。哪个位置最适合在前端上传产品图片、滑块图片、横幅图片和所有动态上传的图片?
storage/app/public
public/img
如果我要去 storage/app/public 位置。我怎样才能将这些图像访问到网站前端?
非常感谢您提供的任何帮助。
使用
public/img
然后在前端用asset函数定位
{{ asset('name_of_file') }}
将图像存储在 storage
目录中。
这是最好的地方,因为您可以使用 Storage
门面,这样可以轻松存储图像。 https://laravel.com/docs/5.6/filesystem
如果您要将存储目的地更改为 CDN(例如 Amazon S3),您也可以像在本地一样使用 Storage
门面。您只需要更改 config/filesystems.php
中的配置,存储图像的代码将保持不变。
一旦你将图像存储在存储目录中,你就可以使用 php artisan storage:link
https://laravel.com/docs/5.6/filesystem#configuration
这将创建一个从您的存储目录到 public 目录的符号链接。
您可以使用助手 asset
来检索图像的路径。 https://laravel.com/docs/5.6/helpers#method-asset
--
关于如何在存储目录中存储文件的例子有很多:
https://quickadminpanel.com/blog/file-upload-in-laravel-the-ultimate-guide/
https://scotch.io/tutorials/understanding-and-working-with-files-in-laravel