cgm225 Posted July 6, 2007 Share Posted July 6, 2007 I want to output an RSS feed based on text in identically named files located in different subdirectories (at the same level). So the structure looks something like: /dir/subdir1/text.txt, /dir/subdir2/text.txt, /dir/subdir3/text.txt, etc. Therefore, how can I create an array of these subdirectory names, and then loop through those directories to echo the text.txt content? Thank you all in advance! cgm225 Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 what??? explain more Quote Link to comment Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 Sorry.. I have photo albums (subdirectories) that have a text file (id.txt) with the title of the album in them. I want to grab that information for each album, and then use it for an RSS feed I am creating. Does that help? Thanks again! Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 $handle = @fopen('yourfile...', "r"); if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 4096); } fclose($handle); } or use file() function to have the text content in an array try that Quote Link to comment Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 Thank you! How do I loop that action through all existing album directories? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 iy you have the array if array are being set by u foreach($array_dir as $dir) { $handle = @fopen('$dir', "r"); if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 4096); } fclose($handle); } } Quote Link to comment Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 Last question.. How do I create an array of those directories? Thank you so much! Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 <?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { // echo "$file\n"; $handle = @fopen('$file', "r"); if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 4096); } fclose($handle); } } or try that } closedir($handle); } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 the last sample are better but for your q $dir=array('dir1','dir2' .....etc) Quote Link to comment Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 How do I get actually get the directory names for the array? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 i suggest use this <?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { // echo "$file\n"; $handle = @fopen('$file', "r"); if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 4096); } fclose($handle); } } or try that } closedir($handle); } ?> thats better $handle supply a dir for this 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.