"; $rtn .= "
"; $rtn .= "
"; $rtn .= "
\n"; $rtn .= "
" . basename($file) . "
\n"; $rtn .= "
Size: " . format_size($file) . "
Last modified: " . date("D. F jS, Y - h:ia", filemtime($file)) . "
\n"; $rtn .= "
\n"; $rtn .= "
\n"; $rtn .= "
"; return $rtn; } // RECURSIVE FUNCTION TO BUILD THE BLOCKS function build_blocks( $items, $folder ) { global $ignore_file_list, $ignore_ext_list, $sort_by, $toggle_sub_folders, $ignore_empty_folders; $objects = array(); $objects['directories'] = array(); $objects['files'] = array(); foreach($items as $c => $item) { if( $item == ".." OR $item == ".") continue; // IGNORE FILE if(in_array($item, $ignore_file_list)) { continue; } if( $folder && $item ) { $item = "$folder/$item"; } $file_ext = getFileExt($item); // IGNORE EXT if(in_array($file_ext, $ignore_ext_list)) { continue; } // DIRECTORIES if( is_dir($item) ) { $objects['directories'][] = $item; continue; } // FILE DATE $file_time = date("U", filemtime($item)); // FILES if( $item ) { $objects['files'][$file_time . "-" . $item] = $item; } } foreach($objects['directories'] as $c => $file) { $sub_items = (array) scandir( $file ); if( $ignore_empty_folders ) { $has_sub_items = false; foreach( $sub_items as $sub_item ) { $sub_fileExt = getFileExt( $sub_item ); if( $sub_item == ".." OR $sub_item == ".") continue; if(in_array($sub_item, $ignore_file_list)) continue; if(in_array($sub_fileExt, $ignore_ext_list)) continue; $has_sub_items = true; break; } if( $has_sub_items ) echo display_block( $file ); } else { echo display_block( $file ); } if( $toggle_sub_folders ) { if( $sub_items ) { echo "
"; build_blocks( $sub_items, $file ); echo "
"; } } } // SORT BEFORE LOOP if( $sort_by == "date_asc" ) { ksort($objects['files']); } elseif( $sort_by == "date_desc" ) { krsort($objects['files']); } elseif( $sort_by == "name_asc" ) { natsort($objects['files']); } elseif( $sort_by == "name_desc" ) { arsort($objects['files']); } foreach($objects['files'] as $t => $file) { $fileExt = getFileExt($file); if(in_array($file, $ignore_file_list)) { continue; } if(in_array($fileExt, $ignore_ext_list)) { continue; } echo display_block( $file ); } } // GET THE BLOCKS STARTED, FALSE TO INDICATE MAIN FOLDER $items = scandir( dirname(__FILE__) ); build_blocks( $items, false ); ?>
Free PHP File Directory Script
(
GitHub
)