【发布时间】:2019-03-17 16:58:43
【问题描述】:
我目前通过文件输入存储图像,如下所示:
<input type="file" name="images" class="form-control">
在 store 函数中,我像这样存储文件和 url:
$blog = new Blog;
$path = Storage::putFile('image', $request->file('images'));
$url = Storage::url($path);
$blog->file = $url;
$blog->save();
效果很好。作为 tinker 中的路径,我为每个博客 ($blog->file) 获得了以下响应:
"/storage/images/GmjAKA6FkId7vli2aw1oq2Z3MkAzZQRxGPoQeVud.jpeg"
要在视图部分显示图像,我使用:
<img src="asset/{{ $blog->file}}" alt="" class="card-img-top">
打印出来的:
<img src="asset/storage/images/GmjAKA6FkId7vli2aw1oq2Z3MkAzZQRxGPoQeVud.jpeg" alt="" class="card-img-top">
在控制台中。
在 storage/images 中,我还可以看到所有上传的图像。 但是,在我的文本编辑器中,存储和图像之间有一个“app”文件夹,如下所示:
"storage/app/images"
这就是没有图像显示的原因。
既然我使用的是 Storage.put,为什么 Storage 将路径保存为“storage/images/”而不是“storage/app/images”?
文件系统.php:
<?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", "sftp", "s3", "rackspace"
|
*/
'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'),
],
],
];
我之前跑过php artisan link:storage(在文档中说明)。
如果有人知道是什么原因造成的,我会很高兴听到它!
提前谢谢大家!
【问题讨论】: