From ee02f08bdb54d2882b4b97e99979aa070a4aed93 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Wed, 14 Oct 2015 14:43:03 +0200 Subject: [PATCH] Prevent warnings when reading the directory fails (There will still be error messages) --- h5p.classes.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 06cd47c..1682a76 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1578,16 +1578,19 @@ Class H5PExport { */ private static function populateFileList($dir, &$files, $relative = '') { $strip = strlen($dir) + 1; - foreach (glob($dir . DIRECTORY_SEPARATOR . '*') as $file) { - $rel = $relative . substr($file, $strip); - if (is_dir($file)) { - self::populateFileList($file, $files, $rel . '/'); - } - else { - $files[] = (object) array( - 'absolutePath' => $file, - 'relativePath' => $rel - ); + $contents = glob($dir . DIRECTORY_SEPARATOR . '*'); + if (!empty($contents)) { + foreach ($contents as $file) { + $rel = $relative . substr($file, $strip); + if (is_dir($file)) { + self::populateFileList($file, $files, $rel . '/'); + } + else { + $files[] = (object) array( + 'absolutePath' => $file, + 'relativePath' => $rel + ); + } } } }