【发布时间】:2020-12-22 11:49:49
【问题描述】:
我有一个带有管理员和客户端的项目。我决定将两者分开,有些事情开始后悔,但我已经走得太远了,无法回去合并它们。无论如何,管理部分基本上是用于将内容上传到数据库中,然后对客户端可见。上传的文件保存在独立于管理员和客户端根文件夹的文件夹中。
我上传文件没有问题,在尝试显示上传的文件时出现问题,这让我想到了我的问题。如何访问根文件夹以外的文件夹中保存的文件?
文件夹结构
- 管理文件夹
- 保存上传文件的文件夹(名为“common”)
- 客户端文件夹
Filesystem.php(客户端)
<?php
返回 [
/*
|--------------------------------------------------------------------------
| 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", "sftp", "s3"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'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'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
],
'common' => [
'driver' => 'local',
'root' => '../common/common/',
],
],
/*
|--------------------------------------------------------------------------
| 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'),
],
];
获取文件的 php 脚本
$img = DB::table('product_images') #Accessing file path from database
->where('products_id', $id)
->get()->first();
$img_name = $img->img;
return Storage::disk('common')->path($img_name);
【问题讨论】:
-
你上传文件的路径是什么?
-
C:\wamp64\www\ngugi\common\common
-
什么是“问题”?您尝试过什么解决方法?