Skip to content

Instantly share code, notes, and snippets.

@kazimolmez
Created May 18, 2018 10:39
Show Gist options
  • Save kazimolmez/e4f257e5361360d7a7ae963119f6d899 to your computer and use it in GitHub Desktop.
Save kazimolmez/e4f257e5361360d7a7ae963119f6d899 to your computer and use it in GitHub Desktop.
PHP Recursive Dir Function
<?php
function Recursive_Dir($anadizin){
$dosyalar = array();
$dizinler = array();
$dizin = (substr($anadizin, -1) == '/') ? substr($anadizin, 0, -1) : $anadizin;
if(is_dir($dizin)){
if($islem = opendir($dizin)){
while(false !== ($dosya = readdir($islem))){
if($dosya != "." && $dosya != ".."){
$yer = $dizin.'/'.$dosya;
if(is_dir($yer)){
$dosyalar = array_merge($dosyalar, Recursive_Dir($yer));
array_push($dizinler, $yer);
} else {
array_push($dosyalar, $yer);
}
}
}
closedir($islem);
} else {
die('Could not open directory.');
}
} else {
die('Invalid directory.');
}
return $dosyalar;
}
$res = Recursive_Dir("./");
foreach ($res as $dir) {
echo $dir."<br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment