2016-03-14 51 views
-1

我试图让我的目录中的所有文件的内容和我得到一个错误,指出如何获取文件的内容Laravel 5.1

ErrorException在Util.php行114: 的preg_match ()期望参数2是字符串,数组给定

。以下是我正在使用的代码。

public function store(Request $request) 
{ 
    $directory = storage_path('app/xmlentries/uploads'); 
    $files = File::files($directory); 
    foreach ($files as $file)   
    { 
     $contents = Storage::get($file); 
     dd($contents);   
    } 

如何获取我的所有文件在这个文件夹中的内容?

+0

哪行代码引发该错误?你能发布完整的错误吗? – avip

+0

我已编辑完整错误的问题。调用错误的文件位于vendor/league/flysystem/src/Util.php中。当然,错误是由我的代码而不是Util.php文件造成的。 – jaahvicky

+0

你是否确认循环内的'$ file'总是一个字符串而不是数组? – drew010

回答

0

试试这个:

$directory = storage_path('app/xmlentries/uploads/'); 

foreach (glob($directory . "*") as $file) { 
    $fileContent = file_get_contents($file); 
    dd($fileContent); // change this per your need 
} 

请注意,这将显示的第一个文件,然后停止!

+0

它不显示文件中的内容。只显示空的引号 - **“”**。 – jaahvicky

+0

你可以只是dd($文件)在循环内,让我知道它显示了什么? –

+0

它输出** app/xmlentries /上传的storage_path ** – jaahvicky