5
RecursiveDirectoryIterator
似乎給我從我的本地和實時服務器兩種不同的結果,php RecursiveDirectoryIterator:如何用點和雙點排除目錄路徑?
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);
本地主機,
(
[0] => core/model/
[1] => core/helper/
[2] => core/ext/
)
直播服務器,
(
[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/../
)
所以,我怎麼能排除目錄路徑與a點和雙點?
編輯:
Live服務器 - PHP版本,27年3月5日 本地主機 - PHP版本5.5
太好了!我正在尋找相同的東西,我手工排除它們(如果點/點繼續) – Ion
我試過了。但仍然不能在我的活服務器上運行... – laukok
然後我想我們需要更多關於您的服務器的信息,您正在運行的PHP版本等(因此更新您的問題) – Brice