Jump to content

PHP get images filename...not working


PlagueInfected

Recommended Posts

here's what I got

 

<?php 
// starting directory. Dot means current directory
$basedir = "img/portfolio";

// function to count depth of directory 
function getdepth($fn){
  return (($p = strpos($fn, "/")) === false) ? 0 : (1 + getdepth(substr($fn, $p+1)));
}

// function to print a line of html for the indented hyperlink
function printlink($fn){
  $indent = getdepth($fn); // get indent value
  echo "<li class=\"$indent\"><a href=\"http://plagueinfected.com/img/portfolio/$fn\"><img src=\"http://plagueinfected.com/img/portfolio/thumbnails/$fn\">"; //print url
$handle = fopen($fn, "r"); //open web page file
$filestr = fread($handle, 1024); //read top part of html
fclose($handle); //clos web page file
  echo "</a><br>\n"; //finish html
}

// main function that scans the directory tree for web pages 
function listdir($basedir){
    if ($handle = @opendir($basedir)) { 
        while (false !== ($fn = readdir($handle))){ 
            if ($fn != '.' && $fn != '..'){ // ignore these
                $dir = $basedir."/".$fn; 
                if (is_dir($dir)){ 
                    listdir($dir); // recursive call to this function
                } else { //only consider .html etc. files
                    if (preg_match("/[^.\/].+\.(jpg|gif|png)$/",$dir,$fname)) {
                       printlink($fname[0]); //generate the html code
                    }
							} 
            } 
        } 
        closedir($handle); 
    } 
} 
// function call 
listdir($basedir); //this line starts the ball rolling
?>

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/
Share on other sites

no output

 

here's how I coded it.

 

<?php 
// starting directory. Dot means current directory
$basedir = "img/portfolio";

// function to count depth of directory 
function getdepth($fn){
  return (($p = strpos($fn, "/")) === false) ? 0 : (1 + getdepth(substr($fn, $p+1)));
}

// function to print a line of html for the indented hyperlink
function printlink($fn){
  $indent = getdepth($fn); // get indent value
  echo $fn . "<br />";
}

// main function that scans the directory tree for web pages 
function listdir($basedir){
    if ($handle = @opendir($basedir)) { 
        while (false !== ($fn = readdir($handle))){ 
            if ($fn != '.' && $fn != '..'){ // ignore these
                $dir = $basedir."/".$fn; 
                if (is_dir($dir)){ 
                    listdir($dir); // recursive call to this function
                } else { //only consider .html etc. files
                    if (preg_match("/[^.\/].+\.(jpg|gif|png)$/",$dir,$fname)) {
                       printlink($fname[0]); //generate the html code
                    }
							} 
            } 
        } 
        closedir($handle); 
    } 
} 
// function call 
listdir($basedir); //this line starts the ball rolling

?>

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.