PlagueInfected Posted December 8, 2009 Share Posted December 8, 2009 I'm trying to use PHP to open a certain dir path and to get the filename of jpg, png and gif images than echo it into an html code to be viewed. here's what I got, I can't get my images in html to preview... <?php $dir = "/_img/_v9/portfolio"; // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { if (preg_match("/[^.\/].+\.(jpg|png|gif)$/",$dir,$file)) { while (($file = readdir($dh)) !== false) { echo "<a href=\"../_img/portfolio/$file\" rel=\"lightbox\"><img src=\"../_img/portfolio/thumbnails/$file\" alt=\"\" /></a>"; } } closedir($dh); } } ?> Link to comment https://forums.phpfreaks.com/topic/184378-opendirimage-load-help/ Share on other sites More sharing options...
trq Posted December 8, 2009 Share Posted December 8, 2009 foreach (glob('/_img/_v9/portfolio/.{jpg,png,gif}', GLOB_BRACE) as $file) { $file = basename($file); echo "<a href=\"../_img/portfolio/$file\" rel=\"lightbox\"><img src=\"../_img/portfolio/thumbnails/$file\" alt=\"\" /></a>"; } Link to comment https://forums.phpfreaks.com/topic/184378-opendirimage-load-help/#findComment-973325 Share on other sites More sharing options...
PlagueInfected Posted December 8, 2009 Author Share Posted December 8, 2009 just tried that, here is how i coded it $dir = "/_img/_v9/portfolio"; // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { foreach (glob('/_img/_v9/portfolio/.{jpg,png,gif}', GLOB_BRACE) as $file) { $file = basename($file); echo "<a href=\"../_img/portfolio/$file\" rel=\"lightbox\"><img src=\"../_img/portfolio/thumbnails/$file\" alt=\"\" /></a>"; } closedir($dh); } } it's still blank when viewing Link to comment https://forums.phpfreaks.com/topic/184378-opendirimage-load-help/#findComment-973328 Share on other sites More sharing options...
trq Posted December 8, 2009 Share Posted December 8, 2009 My entire piece of code is all you need. Link to comment https://forums.phpfreaks.com/topic/184378-opendirimage-load-help/#findComment-973329 Share on other sites More sharing options...
PlagueInfected Posted December 8, 2009 Author Share Posted December 8, 2009 just tried the code you gave me, I still get nothing being echoed out Link to comment https://forums.phpfreaks.com/topic/184378-opendirimage-load-help/#findComment-973331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.