Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created December 29, 2015 19:22
Show Gist options
  • Save maxkostinevich/c2396b4f614e2f50fc65 to your computer and use it in GitHub Desktop.
Save maxkostinevich/c2396b4f614e2f50fc65 to your computer and use it in GitHub Desktop.
Get files on server (Recursive function)
<?php
$host='http://'.$_SERVER['SERVER_NAME'];
function get_files($path,&$files = array()){
global $host;
$dir = opendir($path."/.");
while($item = readdir($dir)){
if(is_file($sub = $path."/".$item)){
$file_path = $host.substr( $path, strlen( $_SERVER[ 'DOCUMENT_ROOT' ] )).'/'.$item;
$file_info =pathinfo($sub);
$files[basename($path)][] = array('url'=>$file_path,'ext'=>$file_info['extension']);
}else{
if($item != "." and $item != ".."){
get_files($sub,$files);
}
}
}
return($files);
}
$files=get_files(dirname(__FILE__));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment