2013-11-01 16 views
5

RecursiveDirectoryIterator bana localhost ve canlı sunucudan iki farklı sonuçlar,php RecursiveDirectoryIterator: dizin yollarını bir nokta ve çift nokta ile nasıl hariç tutabilirsiniz?

define ('WEBSITE_DOCROOT', str_replace('\\', '/', dirname(__FILE__)).'/'); 

print_r(WEBSITE_DOCROOT); 

// List all the class directories in the array. 
$main_directories = array(
    'core/model/', 
    'core/helper/', 
    'core/ext/' 
); 

// Set other vars and arrays. 
$sub_directories = array(); 

// List any sub dirs in the main dirs above and store them in an array. 
foreach($main_directories as $path_directory) 
{ 
    $iterator = new RecursiveIteratorIterator 
    (
     new RecursiveDirectoryIterator(WEBSITE_DOCROOT.$path_directory), // Must use absolute path to get the files when ajax is used. 
     RecursiveIteratorIterator::SELF_FIRST 
    ); 

    foreach ($iterator as $fileObject) 
    { 
     if ($fileObject->isDir()) 
     { 
      //if($fileObject->isDir() === '.' || $fileObject->isDir() === '..') {continue;} 

      // Must trim off the WEBSITE_DOCROOT. 
      $sub_directories[] = preg_replace('~.*?(?=core|local)~i', '', str_replace('\\', '/', $fileObject->getPathname())) .'/'; 
     } 
    } 
} 

// Mearge the main dirs with any sub dirs in them. 
$merged_directories = array_merge($main_directories,$sub_directories); 
print_r($merged_directories); 

localhost'u,

(
    [0] => core/model/ 
    [1] => core/helper/ 
    [2] => core/ext/ 
) 

canlı sunucuyu,

(
    [0] => core/model/ 
    [1] => core/helper/ 
    [2] => core/ext/ 
    [3] => core/model/./ 
    [4] => core/model/../ 
    [5] => core/helper/./ 
    [6] => core/helper/../ 
    [7] => core/ext/./ 
    [8] => core/ext/../ 
) 

Yani, nasıl hariç tutabilirsiniz vermek gibi görünüyor bir nokta ve çift nokta ile dizin yolları?

DÜZENLEME:

Canlı sunucusu - PHP sürümü 5.3.27 Localhost - PHP sürümü 5,5

cevap

21

ile deneyin:

new RecursiveDirectoryIterator(WEBSITE_DOCROOT.$path_directory, RecursiveDirectoryIterator::SKIP_DOTS); 

http://us1.php.net/manual/en/class.filesystemiterator.php

+1

Yüksek, görün! Aynı şeyi arıyordum, onları el ile dışlıyordum (eğer nokta/dotdot devam ediyor) – Ion

+0

Denedim. ama hala benim sunucuda çalışmıyor ... – laukok

+0

O zaman sunucunuz hakkında daha fazla bilgiye, çalıştırmakta olduğunuz PHP sürümüne vb. ihtiyaç duyacağımızı tahmin ediyorum (sonuç olarak sorunuzu güncelleyin) – Brice

İlgili konular