PlagueInfected Posted January 20, 2010 Share Posted January 20, 2010 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 More sharing options...
Buddski Posted January 20, 2010 Share Posted January 20, 2010 Try echoing the values you are getting in $fname.. It might not be what you are expecting.. Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998587 Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 just tried it,no joy Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998618 Share on other sites More sharing options...
Buddski Posted January 20, 2010 Share Posted January 20, 2010 What do you mean no joy? did you get any output at all? Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998620 Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 no joy = nothing lol I got no output at all I echoed $fname and even replaced $fn with $fname and I got no output Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998622 Share on other sites More sharing options...
Buddski Posted January 20, 2010 Share Posted January 20, 2010 What happens if you do this. function printlink($fn){ echo $fn.'<br/>'; .... the rest of your printlink code Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998625 Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 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 https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998628 Share on other sites More sharing options...
Buddski Posted January 20, 2010 Share Posted January 20, 2010 I tested your code and it works fine on my server.. Have you got error_reporting turned on, you may be getting some errors which are stopping script execution.. Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998634 Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 tbh I don't know how to turn it on, lol. Still new to PHP. for the directory path, would I need to include the full URL? Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998640 Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 nvm, found out how to turn it on. It isn't giving me any message or anything. and I can't a single output =/ I'm using hostgator as my host? would how they structure the files have something to do with it. Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998643 Share on other sites More sharing options...
Buddski Posted January 20, 2010 Share Posted January 20, 2010 Ive never used hostgator.. You need to remove the error suppression from the opendir call if ($handle = @opendir($basedir)) { should be if ($handle = opendir($basedir)) { Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998646 Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 ace got it to work, for some reason now the URL goes to... home/jpmarine/public_html/img/portfolio/velvetacidchrist.jpg anyway to only keep the filename itself? velvetacidchrist.jpg Link to comment https://forums.phpfreaks.com/topic/189143-php-get-images-filenamenot-working/#findComment-998647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.