问题描述
我托管网站的服务器不支持 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 中的文件直接上传到公共文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!