Laravel 5.3 store and read file directories

穿精又带淫゛_ 提交于 2019-12-23 19:03:09

问题


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.
    }   
}

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

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.


回答1:


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


来源:https://stackoverflow.com/questions/42091445/laravel-5-3-store-and-read-file-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!