가 나는 내가 깨끗한 URL을 가질 수 있도록 내 사이트 설정 및 파일 자체가 다양한 수준에있다 의 폴더. 그것을 관리하기 위해 다음 스크립트를 사용하여 페이지에 더 멀리 포함시킵니다. 그것은 현재 모든 pageload에 사용하고, 나는 단지 내가 새 파일을 추가 할 때를 업데이트해야 될 때
function listFolderFiles($dir,$exclude){
global $flist;
$ffs = scandir($dir);
foreach($ffs as $ff)
{
if(is_array($exclude) and !in_array($ff,$exclude))
{
if($ff != '.' && $ff != '..')
{
if(!is_dir($dir.'/'.$ff))
{
}
if(is_dir($dir.'/'.$ff))
{
listFolderFiles($dir.'/'.$ff,$exclude);
}
if((is_dir($dir.'/'.$ff)) != 1 && strtolower(substr($ff, strrpos($ff, '.') + 1)) == 'php')
{
$name = basename($ff, ".php");
$flist[] .= $name;
}
}
}
}
}
listFolderFiles('content/',array('filelist.php'));
$removing = array('_en','_es');
$pages = str_replace($removing, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Beginner/',array('filelist.php'));
$removing = array('_en','_es');
$beginner = str_replace($removing, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Intermediate/',array('filelist.php', $beginner));
$removingi = array('_en','_es');
$intermediate = str_replace($removingi, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Advanced/',array('filelist.php', $beginner));
$removinga = array('_en','_es');
$advanced = str_replace($removinga, "", $flist);
는이 코드를 실행하는 빠른 방법이있다.
사이드 노트 :'global $ flist; '의 용도는 무엇입니까? 왜 함수에서 $ flist를 반환하지 않는 것이 좋을까요? –
필요한 파일 만 포함하는 것이 어떻습니까? – Ibu
디렉토리 반복자를 보았습니까? http://php.net/manual/en/directoryiterator.construct.php – Drewdin