Created
June 11, 2013 15:16
-
-
Save AliMD/5757711 to your computer and use it in GitHub Desktop.
Get list of file in directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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