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
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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.