Класс, который читает содержимое директории и выводит список только каталогов. По идее так должно быть, но в итоге массив с директориями получается пустым, хотя каталоги есть.
CODE ( text):
скопировать код в буфер обмена
class directory { // Path to chosen directory var $dir_path; // Array of existen directories var $dir_list; // Name of a chosen directory var $dir_name; // Class construct function directory() { $dir_list = array(); } // Read content of chosen directory function read_dir() { $this->handle = @opendir($this->dir_path); if(!$this->handle) { $this->halt("Unable to open chosen directory."); } while($this->dir = readdir($this->handle)) { if($this->dir != "." && $this->dir != ".." && is_dir($this->dir)) { @array_push($this->dir_list, $this->dir); } }; closedir($this->handle); return $this->dir_list; } // Create new directory function mk_new_dir() { $this->mk_dir = @mkdir($dirname, 0770); if(!$this->mk_dir) { $this->halt("Unable to create new directory or directory exist."); } return; } // Delete chosen directory function delete_dir() { $this->del_dir = @rmdir($dirname); if(!$this->del_dir) { $this->halt("Unable to delete chosen directory."); } return; } // If error, display it function halt($msg) { $error_1 = "<center><small><b>Error:</b> "; $error_2 = "</small></center>"; die($error_1."".$msg."".$error_2); } }; $dr = new directory; $dr->dir_path = $DOCUMENT_ROOT; $dr->read_dir(); print_r($dr->dir_list);
Что делать? Почему массив dir_list пустой?
|