gpt4 book ai didi

php - Laravel Storage::disk()->url();不能正常工作

转载 作者:行者123 更新时间:2023-12-04 14:25:44 24 4
gpt4 key购买 nike

您好,我在 Laravel 中遇到了麻烦。

我想为一些东西(xls、图像、pdf 等)创建私有(private)存储。
在 storage/app/public 目录中一切正常,但我不想要它,我想要我的目录,如 storage/app/products/{id}/

首先看看我的代码:

filesystem.php

   'disks' => [

'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],

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

我创建了新的数组“生产”

ProductionController.php
public function file()
{

return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';

}

web.php(路由)
Route::group([
'middleware'=>'roles',
'roles'=>['Administrator','Prefabrykacja','Dyrektor Prefabrykacji']
], function () {
Route::get('/Produkcja',[
'uses'=>'ProductionController@index',
'as'=>'production.index']);
Route::post('/Produkcja/create',[
'uses'=>'ProductionController@create',
'as'=>'production.create']);


Route::get('/Produkcja/file',[
'uses'=>'ProductionController@file',
'as'=>'production.file']);
});

如果我回来
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';

或者
return '<img src="'.Storage::disk('local')->url('7/2.png').'">';

结果是一样的。这两行从 storage/app/public/7/2.png 返回的图像将不显示图像 storage/app/products/7/2.png

如何显示产品文件夹中的图像并将资源限制为指定角色?

问候

最佳答案

首先,您可能缺少这样的符号链接(symbolic link) public ( Local URL Host Customization )。此外,您需要指定 url参数如 public并更改 visibilitypublic为了让其他人看到你的文件。

filesystem.php:

'disks' => [

'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],

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

'productions' => [
'driver' => 'local',
'root' => storage_path('app/productions'),
'url' => env('APP_URL') . '/productions', // added line (directory within "public")
'visibility' => 'public', // modified visibility
],
],

还要确保在 public/productions 创建符号链接(symbolic link)这将指向 storage/app/productions目录。您可以使用以下命令执行此操作(例如):
cd LARAVEL_PATH && ln -s storage/app/productions public/productions

关于php - Laravel Storage::disk()->url();不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45132441/

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