php 你如何获得 Laravel Storage 文件夹的路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16597392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:25:02  来源:igfitidea点击:

How do you get the path to the Laravel Storage folder?

phplaravel

提问by Garry Pettet

I want to store uploaded images to my Laravel-based web app in a subdirectory of the Laravel storagedirectory. It's the directory at the same hierarchy level as the 'application' and 'public' directories.

我想将上传的图像存储到基于 Laravel 的 Web 应用程序的 Laravelstorage目录的子目录中。它是与“应用程序”和“公共”目录处于同一层次结构级别的目录。

Is there a framework method for doing this? I've searched the docs but can't find one.

是否有执行此操作的框架方法?我搜索了文档,但找不到。

回答by Abishek

In Laravel 3, call path('storage').

在 Laravel 3 中,调用path('storage').

In Laravel 4, use the storage_path()helper function.

在 Laravel 4 中,使用storage_path()辅助函数。

回答by Mark Amery

For Laravel 5.x, use $storage_path = storage_path().

对于 Laravel 5.x,使用$storage_path = storage_path().

From the Laravel 5.0 docs:

来自Laravel 5.0 文档

storage_path

Get the fully qualified path to the storagedirectory.

存储路径

获取storage目录的完全限定路径。

Note also that, for Laravel 5.1 and above, per the Laravel 5.1 docs:

另请注意,对于 Laravel 5.1 及更高版本根据 Laravel 5.1 文档

You may also use the storage_pathfunction to generate a fully qualified path to a given file relative to the storage directory:

$path = storage_path('app/file.txt');

您还可以使用该storage_path函数生成相对于存储目录的给定文件的完全限定路径:

$path = storage_path('app/file.txt');

回答by Sagar Naliyapara

For Laravel version >=5.1

对于 Laravel 版本 >=5.1

storage_path()

存储路径()

The storage_pathfunction returns the fully qualified path to the storage directory:

storage_path函数返回存储目录的完全限定路径:

$path = storage_path();

You may also use the storage_pathfunction to generate a fully qualified path to a given file relative to the storage directory:

您还可以使用该storage_path函数生成相对于存储目录的给定文件的完全限定路径:

$app_path = storage_path('app');
$file_path = storage_path('app/file.txt');

Source:Laravel Doc

来源:Laravel 文档

回答by Mukund Bharti

use this artisan command for create shortcut in public folder

使用此工匠命令在公共文件夹中创建快捷方式

php artisan storage:link

Than you will able to access posted img or file

比您将能够访问发布的 img 或文件

回答by Umang Soni

You can use the storage_path();function to get storage folder path.

您可以使用该storage_path();功能获取存储文件夹路径。

storage_path(); // Return path like: laravel_app\storage

storage_path(); // Return path like: laravel_app\storage

Suppose you want to save your logfile mylog.loginside Log folder of storage folder. You have to write something like

假设您想将mylog.log日志文件保存在存储文件夹的 Log 文件夹中。你必须写一些类似的东西

storage_path() . '/LogFolder/mylog.log'

storage_path() . '/LogFolder/mylog.log'