How to upload files in Laravel directly into public folder?(如何将 Laravel 中的文件直接上传到公共文件夹?)
问题描述
我托管网站的服务器不支持 links,因此我无法运行 php artisan storage:link 将我的存储目录链接到公共目录.我试图在 filesystems.php 中重新制作磁盘配置以直接引用 public 文件夹,但它似乎也不起作用.有没有办法使用 Laravel 库将文件直接上传到公共文件夹中,或者我必须使用 php 方法?提前致谢.
The server which I'm hosting my website does not support links so I cannot run the php artisan storage:link to link my storage directory into the public directory. I tried to remake the disk configuration in the filesystems.php to directly reference the public folder but it didn't seems to work either. Is there a way to upload a file using Laravel libraries directly into the public folder or will I have to use a php method? Thanks in advance.
推荐答案
你可以在config/filesystems.php中创建一个新的存储盘:
You can create a new storage disc in config/filesystems.php:
'public_uploads' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
],
并像这样存储文件:
if(!Storage::disk('public_uploads')->put($path, $file_content)) {
return false;
}
这篇关于如何将 Laravel 中的文件直接上传到公共文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 Laravel 中的文件直接上传到公共文件夹?
基础教程推荐
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
