Created
September 15, 2011 23:22
-
-
Save projectxcappe/1220777 to your computer and use it in GitHub Desktop.
Display Images From A Folder with PHP
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
//Display Images From A Folder with PHP | |
<?php | |
$files = glob("images/*.*"); | |
for ($i=1; $i<count($files); $i++) | |
{ | |
$num = $files[$i]; | |
echo '<img src="'.$num.'" alt="random image">'." "; | |
} | |
?> |
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
//Display Images With Image Name From A Folder | |
<?php | |
$files = glob("images/*.*"); | |
for ($i=1; $i<count($files); $i++) | |
{ | |
$num = $files[$i]; | |
print $num."<br />"; | |
echo '<img src="'.$num.'" alt="random image" />'."<br /><br />"; | |
} | |
?> |
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
//Using lightbox | |
<!-- Start VisualLightBox.com HEAD section --> | |
<link rel="stylesheet" href="engine/css/vlightbox1.css" type="text/css" /> | |
<link rel="stylesheet" href="engine/css/visuallightbox.css" type="text/css" media="screen" /> | |
<script src="engine/js/visuallightbox.js" type="text/javascript"></script> | |
<script src="engine/js/vlbdata.js" type="text/javascript"></script> | |
<!-- End VisualLightBox.com HEAD section --> | |
</head> | |
<body> | |
.... | |
<div id="vlightbox1"> | |
<?php | |
$thumbs = glob("data/facepainting_thumbs/*.*"); | |
$images = glob("data/facepainting_images/*.*"); | |
for ($i=1; $i<count($thumbs); $i++) | |
{ | |
$numT = $thumbs[$i]; | |
$numI = $images[$i]; | |
echo '<a class="vlightbox1" href="'.$numI.'" title="'.$i.'"><img src="'.$numT.'"/></a>'; | |
} | |
?> | |
</div> | |
.... |
This helped a LOT!! Thank you so much. I have a question though, if anyone can help? I want to display the name of the image but without the path. How can I do that?
Change this
print $num ."
";
with this
print basename($num) ."
";
Amazing, thanks.
I wish to see how to display img_name also 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man!! this worked well