php - 当我尝试存储文件时,它不会存储在 storage\app\public
问题描述
我的问题是存储功能不会将歌曲存储在 storage/app/public 中,而是将其存储在 storage/app 中,因此我无法链接它,也无法播放歌曲。
我曾尝试在存储功能中编写公共目录,但是当我尝试播放歌曲时,他没有看到该文件,因为公共目录位于如下路径中:http: //127.0.0.1 :8000/storage/公开/the_song
控制器:
public function store(Request $request)
{
$song = $request->the_song->store('songs');
$music = Music::create([
'sound'=> $song,
'name'=> $request->name
]);
session()->flash('success', 'The Song Successfully Saved');
return redirect(route('music.index'));
}
播放歌曲:
<audio controls autoplay>
<source src="{{ asset($song->sound) }}" type="audio/ogg">
<source src="{{ asset($song->sound) }}" type="audio/mpeg">
</audio>
解决方案
默认情况下,Laravel 使用local
文件系统磁盘(请参阅参考资料config/filesystems.php
)。要保存它,public
您必须明确使用它:
$song = $request->the_song->store('songs', 'public');
并且在检索文件时:
Storage::disk('public')->url($song->sound)
或者您也可以将默认磁盘设置为public
.
推荐阅读
- apache-kafka - 卡夫卡 UNKNOWN_PRODUCER_ID 异常
- java - 只有一个公共 void 方法的类可以称为“服务”吗?
- javascript - 如何在个人资料图像标签中应用 onchange 图像预览
- tensorflow - 用于预测连续输出的卷积神经网络
- javascript - 点击地图上的一个点给出错误的纬度和经度?
- django - 如何在 django 中访问表的列
- spring-boot - 在 Zuul API 网关中剥离前缀
- image-processing - 从发票中提取文本数据
- ruby-on-rails - 操作 Rails 5.0.6 上的电缆连接问题
- phpstorm - 绝对不会在 PhpStorm 终端外壳中打开任何终端