PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи

Страниц (1): [1]

> Найдено сообщений: 1
Daniill0401 Отправлено: 16 Апреля, 2016 - 09:48:41 • Тема: Ответы на вопросы из уроков по php • Форум: Уроки php

Ответов: 67
Просмотров: 4381
Урок номер 8

PHP:
скопировать код в буфер обмена
  1.  
  2.  
  3.  
  4. <?PHP
  5.         class recurseDir {
  6.                 function __construct(){
  7.  
  8.                         }
  9.  
  10.                         public $parent_dir = "";
  11.                         public $bool = false;
  12.  
  13.                 function recurse($dir){
  14.  
  15.                                 chdir($dir);
  16.                                 $dir = getcwd();
  17.  
  18.                                 if(!$this->bool){
  19.                                         $dir_next = array();
  20.                                         preg_match_all("/[0-9a-zA-Z-\.+_@()]+/s", $dir, $dir_next);
  21.                                         $this->parent_dir=$dir_next[0][count($dir_next[0])-1];
  22.                                         $this->bool = true;
  23.                                 }
  24.  
  25.  
  26.  
  27.                                                 echo $dir."\n";
  28.                                 $array = array();
  29.                                 foreach(scandir($dir) as $dir_item){
  30.                                         if($dir_item!="." and $dir_item!=".." and is_dir($dir."/".$dir_item) and !is_link($dir."/".$dir_item)){
  31.                                                 array_push($array, $dir_item);
  32.                                         }
  33.                                 }
  34.  
  35.  
  36.                         if(!count($array)){
  37.                                 unset($array);
  38.  
  39.                                 $this->dir_prev($dir);
  40.                                 unset($dir);
  41.                         }
  42.                                 else {
  43.                                                 $this->recurse($dir."/".$array[0]);
  44.  
  45.                                 }
  46.  
  47.  
  48.  
  49.         }
  50.  
  51.         function dir_prev($dr){
  52.  
  53.                                 chdir($dr);
  54.                                 $dr=getcwd();
  55.                                         $dir_next = array();
  56.                                         $dir_in_dir_next = array();
  57.                                         preg_match_all("/[0-9a-zA-Z-\.+_@()]+/s", $dr, $dir_next);
  58.                                         foreach(scandir($dr."/../") as $dir_item){
  59.                                                
  60.                                                 if($dir_item!="." and $dir_item!=".." and is_dir($dr."/../".$dir_item) and !is_link($dr."/../".$dir_item)){
  61.                                                         array_push($dir_in_dir_next, $dir_item);
  62.                                                 }
  63.                                 }
  64.  
  65.                                 $i = array_search($dir_next[0][count($dir_next[0])-1], $dir_in_dir_next);
  66.  
  67.  
  68.                                 if(count($dir_in_dir_next)==1 || count($dir_in_dir_next)-1==$i){
  69.  
  70.                                         $dir_next = array();
  71.                                         preg_match_all("/[0-9a-zA-Z-\.+_@()]+/s", $dr, $dir_next);
  72.                                         if($dir_next[0][count($dir_next[0])-2]==$this->parent_dir){
  73.  
  74.                                                         exit();
  75.                                         }
  76.  
  77.  
  78.                                         unset($dir_next);
  79.                                         unset($dir_in_dir_next);
  80.                                         $this->dir_prev($dr."/../");
  81.                                 }
  82.  
  83.                                 else {
  84.                                         unset($dir_next);
  85.                                         $this->recurse($dr."/../".$dir_in_dir_next[$i+1]);
  86.                                 }
  87.                         }
  88. }
  89.  
  90.                 $instance = new recurseDir;
  91.                 $instance->recurse("/usr/");
  92.  ?>
  93.  
  94.  

Страниц (1): [1]
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB