Hallo. Ich habe das Problem, dass mein "Verzeichnisleser" ( Methode einer Class ) immer nur einen Durchgang macht. Das heißt er hört nach einer Datei auf, sowohl bei
$task = "del" als auch $task = "read"
PHP
- /**
- * Mehrere Optionen zum bearbeiten eines Verzeichnisses<br/>
- * <ul>Mögliche Operationen:
- * <li>"del": Löscht den gesammten Verzeichnisinhalt
- * <li>"read": Liest den gesammten Verzeichnisinhalt in ein Array
- * </ul>
- *
- * @param string $action durchzuführende Aktion
- * @return boolean Erfolg: true/false
- */
- public function dir( $task = "read" )
- {
- function openAndReadDir( $path, $task )
- {
- if( is_dir( $path ) )
- {
- $dirContent = array();
- $handle = opendir( $path );
- // wenn das verzeichnis erfolgreich geöffnet wurde
- if( $handle )
- {
- while( ( $object = readdir( $handle ) ) !== false )
- {
- if ( $object !== "." AND $object !== ".." )
- // Ordner "." und ".." ignorieren
- {
- $path = $path.$object;
- if( is_dir( $path ) )
- {
- openAndReadDir( $path, $task );
- }
- elseif( is_file( $path ) )
- {
- if( $task === "read" )
- {
- // array_pop( explode() ) --> Strict Standards: Only variables should be passed by reference
- // Lösung: Aufteilung ...
- $temp = explode( ".", $object );
- $dirContent[] = array( "name" => $object, "type" => strtolower( array_pop( $temp ) ), "size" => filesize( $path ) );
- }
- elseif( $task === "del" )
- {
- unlink( $path );
- }
- }
- }
- }
- closedir( $handle );
- }
- return ( $dirContent );
- }
- return ( "Kein Verzeichnis! : ".$path );
- }
- // Zusätzliches Slash für den Fall, dass keines übergeben wurde. Mehrfach-Slashes sind kein Problem
- return ( openAndReadDir( $this->path."/", $task ) );
- }
Ergebniss (das hier funktioniert also anscheinend):
Alles anzeigen
Bin super Dankbar ür Hilfe