我正在尝试将单个图像上传到帖子中,并且一直将其保存为私有图像-哎呀,我什至不知道在哪里可以找到该文件。
PostController.php
...
if ($request->hasFile('photo')) {
$photo = $request->photo;
$ext = $photo->getClientOriginalExtension();
$filename = uniqid() . '.' . $ext;
$photo->storeAs('public/posts/' . $request->user()->id, $filename);
}
...
答案 0 :(得分:0)
storeAs()函数采用三个参数。
storeAs(path,name,options)
“选项”是您指定文件可见性的位置。就您而言:
if ($request->hasFile('photo')) {
$photo = $request->photo;
$ext = $photo->getClientOriginalExtension();
$filename = uniqid() . '.' . $ext;
$photo->storeAs('posts/' . $request->user()->id, $filename,'public');
}