我刚刚托管了我的Laravel应用程序,当我尝试存储任何文件时,路径被复制到数据库,但文件本身无法上传,我尝试更改权限,但没有任何变化。 我已经在存储文件夹中有一些图像,它们显示得很好。storage link
已创建。
控制器
public function addLeague(Request $request) {
$newLeague = new League();
$newLeague->name = $request->input('name');
if ($request->hasFile('logo')) {
$newLeague->logo = $request->logo->store('images');
}
$newLeague->save();
return redirect('/leagues');
}
文件系统
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => env('FILESYSTEM_DRIVER', 'local'),
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "s3", "rackspace"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/public'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
可能你有一个断开的符号链接。若要检查这一点,请访问公用文件夹并键入ls
以查看存储链接。如果它是红色的,你必须修复它:
查找链接指向的位置:readlink -v storage
指向新路径的链接:ln -sfn /path/to/your/storage/public/ storage
参考:修复损坏的符号链接
我遇到了同样的问题,经过大量调试,我设法确定了导致 403 错误的实际问题。
解决方案很简单,在
配置/文件系统.php 在定义public_path和存储路径的位置,必须具有相同/相同的public_path名称和storage_path结束目录名称。
例:
- 不對:
public_path('brands') => storage_path('storage/app/public/brandimages');
这将生成 403 错误,"因为 public_path('品牌'("与"storage_path('../../../品牌形象'("。
- 正确:
public_path('brands') => storage_path('storage/app/public/brands');
现在public_path(">品牌"(和"storage_path('../../../brands'("是相同的,因此,将生成正确的符号链接,从而解决403错误。
使用以下工匠命令生成符号链接
php artisan storage:link
对于相对链接,请使用以下命令
php artisan storage:link --relative
我认为符号链接所有者/组是"root/root",而访问网站的用户是其他用户(例如,在 Plesk 中,访问网站的用户组是"psacli"(。此用户无权执行 root 拥有的符号链接。您必须将符号链接的所有者/组更改为 Web 用户的用户/组。