Laravel 5.3存储和读取文件目录 [英] Laravel 5.3 store and read file directories

查看:104
本文介绍了Laravel 5.3存储和读取文件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在尝试处理文件,但努力弄清楚将文件放置在何处以及如何将它们读回到列表中.

Currently trying to play about with files but struggling to figure out where to put them and how to read them back in a list.

我曾尝试将少量测试文件放入

Ive tried putting few test files into

$files = array();
$dir = opendir(asset('files'); // open the cwd..also do an err check.
while(false != ($file = readdir($dir))) {
    if(($file != ".") and ($file != "..") and ($file != "index.php")) {
            $files[] = $file; // put in array.
    }   
}

,尽管其中包含3个测试文件,但它只是返回空白.

but it just returns blank despite having 3 test files in it.

研究幼虫的食谱和建议说File:allFile()这不是受支持的方法,但让我想知道除了如何从目录读取文件之外,我应该在哪里真正存储要拥有的文件在服务器上.

Looked into larval recipes and suggestions say File:allFile() which isn't a supported method but its got me wondering apart from how to read files from a directory, where should i be really storing files I'm going to have on a server.

推荐答案

Laravel 5.3使用 Storage代替Files .您可以使用以下两种方法之一访问目录中的所有文件:

Laravel 5.3 uses Storage instead of Files. You can access all of the files in a directory using either of these two methods:

use Illuminate\Support\Facades\Storage;

$files = Storage::files($directory);

$files = Storage::allFiles($directory); // Includes subdirectories

这篇关于Laravel 5.3存储和读取文件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆