Skip to content

Instantly share code, notes, and snippets.

@bognerf
Created June 19, 2013 13:50
Show Gist options
  • Save bognerf/5814472 to your computer and use it in GitHub Desktop.
Save bognerf/5814472 to your computer and use it in GitHub Desktop.
Verkürzte Klasse, um Verzeichnisinhalt zu lesen
<?php
namespace fsp;
class FilesystemProvider
{
private $dir;
public $dirContent;
private $activeDirectory;
private $allowed_extensions = array("mp3", "ogg", "wma");
public function __construct($basedir)
{
$this->activeDirectory = $basedir;
}
public function getCurrentDir()
{
return $this->activeDirectory . "/";
}
/**
* @return array('dirs' => SUBDIRECTORIES_IN_CURRENT_DIRECTORIES, 'files' => FILES_IN_CURRENT_DIRECTORY)
*/
public function readdir()
{
$this->dir = new \DirectoryIterator($this->activeDirectory);
$here['files'] = array();
$here['dirs'] = array();
foreach ($this->dir as $fileinfo)
{
if ($fileinfo->isFile() AND in_array($fileinfo->getExtension(), $this->allowed_extensions))
{
$here['files'][] = addslashes($fileinfo->getFilename());
}
if ($fileinfo->isDir() AND !$fileinfo->isDot())
{
$here['dirs'][] = addslashes($fileinfo->getFilename());
}
}
sort($here['files']);
sort($here['dirs']);
$this->dirContent = $here;
return $this->dirContent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment