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? Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
PlagueInfected Posted January 20, 2010 Author Share Posted January 20, 2010 just tried it,no joy Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 ?> Quote Link to comment 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.. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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)) { Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.