Created
June 19, 2013 13:50
-
-
Save bognerf/5814472 to your computer and use it in GitHub Desktop.
Verkürzte Klasse, um Verzeichnisinhalt zu lesen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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