Jump to content

opendir/image load help


PlagueInfected

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.