gpt4 book ai didi

php - Laravel 获取存储在公共(public)文件夹中的文件的公共(public) URL

转载 作者:行者123 更新时间:2023-12-02 02:07:59 25 4
gpt4 key购买 nike

在 Windows 上我有 Xampp。我的应用程序在 Anuglar 和 Laravel 8 中我将文件添加到存储文件夹中的公共(public)文件夹。filesystem.php中的配置:

'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

.env 文件中:

APP_URL=http://localhost:8082/prftbx-crm-api/public

公共(public)文件夹中的文件:

 Directory of C:\xampp\htdocs\crm-api\storage\app\public

06/25/2021 11:01 AM <DIR> .
06/25/2021 11:01 AM <DIR> ..
04/26/2021 10:57 PM 14 .gitignore
06/25/2021 11:01 AM 510 381787c3ad1442cc882ee427e93af805.txt

在 Laravel 中,我使用以下方法返回 url:

$fileDTO->filePath = Storage::url($fileEntity->file_name);

在 View 中我有地址:

/storage/381787c3ad1442cc882ee427e93af805.txt

当我在浏览器中输入 url 时:

http://localhost:8082/crm-api/public/storage/381787c3ad1442cc882ee427e93af805.txt

我收到 404,找不到文件

最佳答案

首先运行以下命令

php artisan storage:link

那么你可以

http://localhost:8082/storage/381787c3ad1442cc882ee427e93af805.txt

保持应用程序 url 为

APP_URL=http://localhost:8082

如文档所述

The public disk included in your application's filesystemsconfiguration file is intended for files that are going to be publiclyaccessible. By default, the public disk uses the local driver andstores its files in storage/app/public.

To make these files accessible from the web, you should create asymbolic link from public/storage to storage/app/public. Utilizingthis folder convention will keep your publicly accessible files in onedirectory that can be easily shared across deployments when using zerodown-time deployment systems like Envoyer.

To create the symbolic link, you may use the storage:link Artisancommand:

php artisan storage:link Once a file has been stored and the symboliclink has been created, you can create a URL to the files using theasset helper:

引用:https://laravel.com/docs/8.x/filesystem#the-public-disk

关于php - Laravel 获取存储在公共(public)文件夹中的文件的公共(public) URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68128685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com