Mdbook

PHP get files from folder

Nov 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $dir_path = dirname(realpath(__FILE__)).'/f/';
  2.     $extensions_array = array('jpg','png','jpeg');
  3.     if(is_dir($dir_path)) {
  4.         $files = scandir($dir_path);
  5.         for($i = 0; $i < count($files); $i++) {
  6.             if($files[$i] !='.' && $files[$i] !='..' && $files[$i] !='.php') {
  7.                 $file = pathinfo($files[$i]);
  8.                 $extension = $file['extension'];
  9.                 if(in_array($extension, $extensions_array)) {
  10.                     echo "<a href='f/$files[$i]' target='_blank'>
  11.                     <div style='background-image: url(/f/$files[$i]);' title='$files[$i]'></div></a>";
  12.                 }
  13.                
  14.             }
  15.         }
  16.     }
Add Comment
Please, Sign In to add comment