Directory.php 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\Core\FileReader;
  3. /**
  4. * Description of Directory
  5. *
  6. * @author INBSX-37H
  7. */
  8. class Directory extends PathValidator
  9. {
  10. public function getFilesList($path, $extension = null, $trimExtensions = false)
  11. {
  12. if (!$this->pathExists($path) || !$this->isPathReadable($path))
  13. {
  14. return [];
  15. }
  16. $list = [];
  17. $files = scandir($path, 1);
  18. if (!$files)
  19. {
  20. return [];
  21. }
  22. foreach ($files as $key => $value)
  23. {
  24. //remove dots and a files with unwanted extensions
  25. if ($value === "." || $value === ".." ||
  26. (is_string($extension) && $extension !=='' && !(stripos($value, $extension) > 0)))
  27. {
  28. unset($files[$key]);
  29. continue;
  30. }
  31. $list[] = $trimExtensions ? str_replace($extension, '', $value) : $value;
  32. }
  33. return $list;
  34. }
  35. }