Last active
November 17, 2015 02:41
-
-
Save leowebguy/03250646649b041828be to your computer and use it in GitHub Desktop.
List server directory files using php and display into a page.
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
<html lang="en" class="no-js"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | |
<style> | |
.frame { | |
width: 30%; | |
height: 30%; | |
background-size: cover; | |
float: left; } | |
.label { | |
float:left; | |
color: #fff; | |
background-color: rgba(0,0,0,0.6); | |
padding: 2px; | |
position: relative; | |
top: 0; | |
left: 0; } | |
</style> | |
</head> | |
<body> | |
<?php | |
//Path to folder which contains images | |
$dirname = "/home/deploy/public_html/mywebsite/img/"; | |
//Use glob function to get the files | |
//Note that we have used " * " inside this function. If you want to get only JPEG or PNG use | |
//below line and commnent $files variable currently in use | |
$files = glob($dirname."*"); | |
//Display image using foreach loop | |
foreach($files as $file) { | |
$file = str_replace($dirname, "", $file); | |
if (substr_count($file, 'jpg') == 1) { | |
//print the image to browser with anchor tag (Use if you want really :) ) | |
echo '<div class="frame" style="background:url(http://mywebsite.com/img/'. $file .') no-repeat center center; background-size:cover;"><div class="label">'. $file .'</div></div>'; | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment