【发布时间】:2020-08-15 13:31:49
【问题描述】:
我试图弄清楚如何访问存储的文件,在这种情况下是个人资料图片。
理想情况下,我想将它们保存在“个人资料图片”文件夹中。可以使用指向 storage/app/public/profilepictures 的符号链接在 public/profilepictures 目录中
我现在的代码如下所示:
控制器:
//store our image in the profilepics directory
$profilepicpath = request('profilepic')->store('profilepictures', 'public');
//actually write all the data to the database
auth()->user()->profile()->create([
'profilepic' => $profilepicpath,
'dateofbirth' => $data['dateofbirth'],
'about' => $data['about'],
'zipcode' => $data['zipcode'],
'state' => $data['state']
]);
查看:
<div class="data" style="visibility: hidden;">
{{$profile = App\profile::find(Auth::user()->id)}}
</div>
<div class="profile-wrapper">
<div class="profile-grid">
<div class="profilepic">
<img class="profilepic-image" src={{asset($profile['profilepic'])}}>
</div>
Config 中的 Filesystems.php:
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
//public_path('storage') => storage_path('app/public'),
public_path('profilepictures') => storage_path('app/public/profilepictures'),
],
有人知道为什么这不起作用吗?
如果我从应该在视图中显示的位置复制图像位置,我会得到以下结果之一:
或者
这两个链接都不起作用,如果我尝试在浏览器中访问它,我只会收到错误 404。虽然基于查看目录结构,我认为第一个应该可以工作。
大家有什么建议吗?
我在安装在 ubuntu 物理桌面上的 virtualbox vm 上的 homestead 上运行 laravel,到目前为止我已经为此尝试了许多不同的配置,包括编辑 .htaccess 文件都没有成功。
【问题讨论】:
标签: php laravel symlink public homestead