2016-03-14 47 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