Skip to content

Instantly share code, notes, and snippets.

@AliMD
Created June 11, 2013 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AliMD/5757711 to your computer and use it in GitHub Desktop.
Save AliMD/5757711 to your computer and use it in GitHub Desktop.
Get list of file in directory.
<?php
function getFiles($path,$type){
$files = scandir($path);
foreach ($files as $file){
$temp = explode('.',$file);
$file_type = strtolower( end($temp) ); // JPG => jpg
if($file_type == $type){
$images[] = $file;
}
}
return $images;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<title>test</title>
</head>
<body>
<?php
include('lib.php');
$imgs = getFiles('images','jpg');
foreach($imgs as $img){
echo "<img src='images/$img' />";
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment