Içteki dizin adını almak nasıl

1 Cevap php

Ben çıkış için iç dizin adının adına dayalı bir sınıf çalışıyorum, ama sağ olsun olamaz. Herhangi bir yardım çok mutluluk duyacağız. Bu bir php_file_tree var, aşağıda bölüm sayılı # 39 bakın lütfen:

    function php_file_tree_dir($directory, $return_link, $extensions = array(), $first_call = TRUE) {
  // Get and sort directories/files
  if (function_exists("scandir")) {
    $file = scandir($directory);
  }
  else { 
    $file = php4_scandir($directory);
  }
  natcasesort($file);
  // Make directories first
  $files = $dirs = array();

  foreach ($file as $this_file) {
    if (is_dir("$directory/$this_file")) {
      $dirs[] = $this_file;
    }
    else $files[] = $this_file;
  }

  $file = array_merge($dirs, $files);

  // Filter unwanted extensions
  if (!empty($extensions)) {
    foreach (array_keys($file) as $key) {
      if (!is_dir("$directory/$file[$key]")) {
        $ext = substr($file[$key], strrpos($file[$key], ".") + 1);
        if (!in_array($ext, $extensions))unset($file[$key]);
      }
    }
  }
  // Use 2 instead of 0 to account for . and .. "directories"
  if (count($file) > 2) {
    $php_file_tree = "<ul";
    if ($first_call) {
      $php_file_tree .= " class=\"php-file-tree clearfix\"";
      $first_call = FALSE;
    }

    // #39, Here needs to output a class based on innermost directory name
    /*
    else {
      $php_file_tree .= " class=\"innertree ". htmlspecialchars(basename(rtrim($directory, '/'))) ." clearfix\"";
    }
    */

    $php_file_tree .= ">";
    foreach ($file as $this_file) {
      if ($this_file != "." && $this_file != "..") {
        if (is_dir("$directory/$this_file")) {
          // Directory
          $php_file_tree .= "<li class=\"pft-directory\"><a class=\"folder \" href=\"#\">". htmlspecialchars($this_file) ."</a>";
          $php_file_tree .= php_file_tree_dir("$directory/$this_file", $return_link, $extensions, FALSE);
          $php_file_tree .= "</li>";
        }
        else  {
          //$ext = "ext-". substr($this_file, strrpos($this_file, ".") + 1); // need to compare speed with native
          $ext = "ext-". pathinfo($this_file, PATHINFO_EXTENSION);
          $link = str_replace("[link]", base_path() ."$directory/". urlencode($this_file), $return_link);
          $php_file_tree .= "<li class=\"pft-file ". strtolower($ext) ."\"><a class=\"screenshot\" title=". htmlspecialchars($this_file) ." href=\"$link\">". htmlspecialchars($this_file) ."</a></li>";
        }
      }
    }
    $php_file_tree .= "</ul>";
  }
  return $php_file_tree;
}

Aşağıdaki / sonraki dizinleri altında kendi klasör adlarına göre kendi sınıfları sahipken üst dizin her zaman, bir sınıf "php-file-ağacı" olacak.

1 Cevap

Tanrım, aslında zaten iyiydi. Sorun önbellek veya AJAX çağrısı ile kalıcı bir iletişim içine yerleştirilmiş gibi bir şey olarak görünüyor. Ben de dahil olmak üzere, daha önce çeşitli olasılıkları denedim "$ first_call = FALSE;" boşuna. Doğru şimdi çıktı klasör adı, ve net her şey; "$ first_call = YANLIŞ" Ben tekrar dizin revisited Ama ekledi.

Rahatsız ettiğim için özür dilerim, herkes. Teşekkürler