我有一个 Laravel 项目,在这个项目中,我上传一些像这样的图像:
public function storeImages(Request $request,Slider $slider)
{
// Get the uploaded file
$image = $request->file('image');
// Generate unique filename
$filename = time() . '_' . uniqid() . '.' . $image->getClientOriginalExtension();
// Specify the directory to store the image
$directory = 'upload/sliders/images/' . now()->year . '/' . now()->month;
// Store the image in the specified directory
$path = $image->storeAs($directory, $filename);
// Save the image record in the database
$sliderImage = new SliderImages([
'slider_id' => $slider->id,
'image_path' => $path,
]);
$sliderImage->save();
// Redirect or return a response as needed
return redirect()->route('adm.sliders.images.info', ['slider'=>$slider->id,'image'=>$sliderImage->id]);
}
它在本地主机上运行良好。但我不知道为什么它不能在生产模式下的实时服务器上工作。 (图像已正确上传到存储路径,但由于公共目录中不存在图像,因此未显示图像)
这是我的
filesystems.php
:
<?php
return [
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
'adm' => [
'driver' => 's3',
'root' => storage_path('app/adm'),
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
],
/*
|--------------------------------------------------------------------------
| 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' => [
base_path('storage') => storage_path('app/public'),
],
];
现在当我运行
php artisan storage:link
时,它返回:
错误 |链接已存在。
但是,当我检查文件夹
public
时,我没有看到这样的目录:
那么这里出了什么问题呢?我该如何解决这个问题?
您是否更改了文件系统配置上的链接?您的
base_path('storage')
文件夹已经存在,因为这是默认存储文件夹。当然,您不能在链接的同一文件夹上创建链接。尝试将链接配置更改为:
(然后运行
php artisan storage:link
)
'links' => [
public_path('storage') => storage_path('app/public'),
],