├── README.md ├── flat.png └── index.php /README.md: -------------------------------------------------------------------------------- 1 | # Free Super Clean PHP File Directory Listing Script 2 | 3 | Easily display files and folders in a mobile friendly, clean and cool way. Just drop the `index.php` in your folder and you are ready to go. Past versions of this script can be found here: https://halgatewood.com/file-directory-list/ 4 | 5 | ## Options 6 | 7 | At the top of the `index.php` file you have a few settings you can change: 8 | 9 | -- 10 | `$title = "List of Files";` 11 | 12 | This will be the title of your page and also is set to the meta mitle of the document. 13 | 14 | -- 15 | `$color = "light";` 16 | 17 | Change this variable to `dark` when you are feeling down. 18 | 19 | -- 20 | `$ignore_file_list = array( ".htaccess", "Thumbs.db", ".DS_Store", "index.php" );` 21 | 22 | Create an array of files that you do not want to appear in the listing 23 | 24 | -- 25 | `$ignore_ext_list = array( );` 26 | 27 | You can create an array of extensions not to show, for example: 'jpg,png,gif,pdf' 28 | 29 | -- 30 | `$sort_by = "name_asc";` 31 | 32 | This will sort the files, the available options are: name_asc, name_desc, date_asc, date_desc 33 | 34 | -- 35 | `$icon_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+gAAAAyCAYAAADP7vEw....";` 36 | 37 | A data sprite of evenly spaced out icons. You can create your own like the one found here. 38 | 39 | Original: 40 | - https://halgatewood.com/images/icons.png 41 | - https://halgatewood.com/images/icons.psd 42 | 43 | Flat: 44 | - https://halgatewood.com/images/flat.png 45 | - https://halgatewood.com/images/flat.psd 46 | 47 | -- 48 | `$toggle_sub_folders = true;` 49 | 50 | If a folder is clicked on, it will slide down the sub folder. You can turn this off here. 51 | 52 | -- 53 | `$force_download = true;` 54 | 55 | This will add the html download attribute which forces the download in some browsers. 56 | 57 | -- 58 | `$ignore_empty_folders = true;` 59 | 60 | Ability to hide empty folders. 61 | -------------------------------------------------------------------------------- /flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halgatewood/file-directory-list/d6d316a342fcaa66a41aa9779104cbd3157293f4/flat.png -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 63 | 64 | 65 | 66 | <?php echo $title; ?> 67 | 68 | 69 | 70 | 71 | 122 | 123 | 124 |

125 |
126 | ' . $units[$pow] . ""; 147 | } 148 | 149 | function count_dir_files( $dir) 150 | { 151 | $fi = new FilesystemIterator(__DIR__ . "/" . $dir, FilesystemIterator::SKIP_DOTS); 152 | return iterator_count($fi); 153 | } 154 | 155 | function get_directory_size($path) 156 | { 157 | $bytestotal = 0; 158 | $path = realpath($path); 159 | if($path!==false && $path!='' && file_exists($path)) 160 | { 161 | foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) 162 | { 163 | $bytestotal += $object->getSize(); 164 | } 165 | } 166 | 167 | return display_size($bytestotal); 168 | } 169 | 170 | 171 | // SHOW THE MEDIA BLOCK 172 | function display_block( $file ) 173 | { 174 | global $ignore_file_list, $ignore_ext_list, $force_download; 175 | 176 | $file_ext = ext($file); 177 | if( !$file_ext AND is_dir($file)) $file_ext = "dir"; 178 | if(in_array($file, $ignore_file_list)) return; 179 | if(in_array($file_ext, $ignore_ext_list)) return; 180 | 181 | $download_att = ($force_download AND $file_ext != "dir" ) ? " download='" . basename($file) . "'" : ""; 182 | 183 | $rtn = "
"; 184 | $rtn .= ""; 185 | $rtn .= "
"; 186 | $rtn .= "
"; 187 | 188 | if ($file_ext === "dir") 189 | { 190 | $rtn .= "
" . basename($file) . "
"; 191 | $rtn .= "
" . count_dir_files($file) . " files
"; 192 | $rtn .= "
Size: " . get_directory_size($file) . "
"; 193 | 194 | } 195 | else 196 | { 197 | $rtn .= "
" . basename($file) . "
"; 198 | $rtn .= "
Size: " . display_size(filesize($file)) . "
"; 199 | $rtn .= "
Last modified: " . date("D. F jS, Y - h:ia", filemtime($file)) . "
"; 200 | } 201 | 202 | $rtn .= "
"; 203 | $rtn .= "
"; 204 | $rtn .= "
"; 205 | return $rtn; 206 | } 207 | 208 | 209 | // RECURSIVE FUNCTION TO BUILD THE BLOCKS 210 | function build_blocks( $items, $folder ) 211 | { 212 | global $ignore_file_list, $ignore_ext_list, $sort_by, $toggle_sub_folders, $ignore_empty_folders; 213 | 214 | $objects = array(); 215 | $objects['directories'] = array(); 216 | $objects['files'] = array(); 217 | 218 | foreach($items as $c => $item) 219 | { 220 | if( $item == ".." OR $item == ".") continue; 221 | 222 | // IGNORE FILE 223 | if(in_array($item, $ignore_file_list)) { continue; } 224 | 225 | if( $folder && $item ) 226 | { 227 | $item = "$folder/$item"; 228 | } 229 | 230 | $file_ext = ext($item); 231 | 232 | // IGNORE EXT 233 | if(in_array($file_ext, $ignore_ext_list)) { continue; } 234 | 235 | // DIRECTORIES 236 | if( is_dir($item) ) 237 | { 238 | $objects['directories'][] = $item; 239 | continue; 240 | } 241 | 242 | // FILE DATE 243 | $file_time = date("U", filemtime($item)); 244 | 245 | // FILES 246 | if( $item ) 247 | { 248 | $objects['files'][$file_time . "-" . $item] = $item; 249 | } 250 | } 251 | 252 | foreach($objects['directories'] as $c => $file) 253 | { 254 | $sub_items = (array) scandir( $file ); 255 | 256 | if( $ignore_empty_folders ) 257 | { 258 | $has_sub_items = false; 259 | foreach( $sub_items as $sub_item ) 260 | { 261 | $sub_fileExt = ext( $sub_item ); 262 | if( $sub_item == ".." OR $sub_item == ".") continue; 263 | if(in_array($sub_item, $ignore_file_list)) continue; 264 | if(in_array($sub_fileExt, $ignore_ext_list)) continue; 265 | 266 | $has_sub_items = true; 267 | break; 268 | } 269 | 270 | if( $has_sub_items ) echo display_block( $file ); 271 | } 272 | else 273 | { 274 | echo display_block( $file ); 275 | } 276 | 277 | if( $toggle_sub_folders ) 278 | { 279 | if( $sub_items ) 280 | { 281 | echo "
"; 282 | build_blocks( $sub_items, $file ); 283 | echo "
"; 284 | } 285 | } 286 | } 287 | 288 | // SORT BEFORE LOOP 289 | if( $sort_by == "date_asc" ) { ksort($objects['files']); } 290 | elseif( $sort_by == "date_desc" ) { krsort($objects['files']); } 291 | elseif( $sort_by == "name_asc" ) { natsort($objects['files']); } 292 | elseif( $sort_by == "name_desc" ) { arsort($objects['files']); } 293 | 294 | foreach($objects['files'] as $t => $file) 295 | { 296 | $fileExt = ext($file); 297 | if(in_array($file, $ignore_file_list)) { continue; } 298 | if(in_array($fileExt, $ignore_ext_list)) { continue; } 299 | echo display_block( $file ); 300 | } 301 | } 302 | 303 | // GET THE BLOCKS STARTED, FALSE TO INDICATE MAIN FOLDER 304 | $items = scandir( dirname(__FILE__) ); 305 | build_blocks( $items, false ); 306 | ?> 307 | 308 | 309 | 320 | 321 |
322 |
Free PHP File Directory Script (GitHub)
323 | 324 | 325 | --------------------------------------------------------------------------------