headmine Posted December 10, 2009 Share Posted December 10, 2009 Is there an easier way to do this? I am trying to get create a dyamic array based on files within the folder. foreach (glob("*.jpg") as $filename) { $items = array("title" => $filename) } $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $output .= '<rss version="2.0">'; $output .= "<channel>"; $output .= "<title>" . $channel["title"] . "</title>"; $output .= "<description>" . $channel["description"] . "</description>"; $output .= "<link>" . $channel["link"] . "</link>"; $output .= "<copyright>" . $channel["copyright"] . "</copyright>"; foreach ($items as $item) { $output .= "<item>"; $output .= "<title>" . $item["title"] . "</title>"; $output .= "</item>"; } $output .= "</channel>"; $output .= "</rss>"; header("Content-Type: application/rss+xml; charset=ISO-8859-1"); echo $output; ?> This doesn't even work correctly. Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/ Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 Not sure why your using two loops but your first one would need to be.... foreach (glob("*.jpg") as $filename) { $items[] = array("title" => $filename) } in order for your second one to work. Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974419 Share on other sites More sharing options...
headmine Posted December 10, 2009 Author Share Posted December 10, 2009 What im trying to do is create a dynamic rss image feed based on images within a folder. Your array fix helped me but its . Still not working foreach (glob("*.jpg") as $filename) { $items[] = array("img_local" => $filename); } $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $output .= '<rss version="2.0">'; $output .= "<channel>"; $output .= "<title>" . $channel["title"] . "</title>"; $output .= "<description>" . $channel["description"] . "</description>"; $output .= "<link>" . $channel["link"] . "</link>"; $output .= "<copyright>" . $channel["copyright"] . "</copyright>"; foreach ($items as $item) { $output .= "<item>"; $output .= "<content><img src=\"http://LOCATION/" . $item["img_local"] . "\" /></content>"; $output .= "</item>"; } $output .= "</channel>"; $output .= "</rss>"; header("Content-Type: application/rss+xml; charset=ISO-8859-1"); echo $output; Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974433 Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 Define 'Still not working'. Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974438 Share on other sites More sharing options...
headmine Posted December 10, 2009 Author Share Posted December 10, 2009 When you view the file through a web browser it looks like a feed but no images show up. If I remove <img src= etc then the name of the files will appear. But as soon as I add img tags everything disappears. Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974447 Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2009 Share Posted December 10, 2009 thats because your <item> should be embedded in another tag say <items> <item>blah blah</item> </items Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974448 Share on other sites More sharing options...
headmine Posted December 10, 2009 Author Share Posted December 10, 2009 thats because your <item> should be embedded in another tag say <items> <item>blah blah</item> </items I don't understand? Like this foreach ($items as $item) { $output .= "<items>"; $output .= "<item>"; $output .= "<content><img src=\"http://LOCATION/" . $item["img_local"] . "\" /></content>"; $output .= "</item>"; $output .= "</items>"; } Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974449 Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 What does the output of the code look like? Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974541 Share on other sites More sharing options...
headmine Posted December 10, 2009 Author Share Posted December 10, 2009 I've made a few edits.... Here is the link to the page: http://headmine.org/the-test/index.php I've only been able to get the icons to show with links. I'd like the images to display. here is the updated code <?php $channel = array("title" => "Headmine", "description" => "Example of a RSS feed.", "link" => "http://headmine.org", "copyright" => "Copyright (C) 2009 headmine.org"); foreach (glob("*.jpg") as $filename) { $items[] = array("img" => $filename); } $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $output .= '<rss version="2.0">'; $output .= "<channel>"; $output .= "<title>" . $channel["title"] . "</title>"; $output .= "<description>" . $channel["description"] . "</description>"; $output .= "<link>" . $channel["link"] . "</link>"; $output .= "<copyright>" . $channel["copyright"] . "</copyright>"; foreach ($items as $item) { $output .= "<item>"; $output .= "<enclosure length=\"1234567\" type=\"image/jpeg\" url=\"http://johnregalado.com/the-test/". $item["img"] ."\" />"; $output .= "<url>http://headmine.org/the-test/". $item["img"] ."</url>"; $output .= "</item>"; } $output .= "</channel>"; $output .= "</rss>"; header("Content-Type: application/rss+xml; charset=utf-8"); echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974551 Share on other sites More sharing options...
headmine Posted December 10, 2009 Author Share Posted December 10, 2009 Sorry output is: <?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Headmine</title><description>Example of a RSS feed.</description><link>http://headmine.org</link><copyright>Copyright (C) 2009 headmine.org</copyright><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/a-river-runs-though-it.jpg" /><url>http://headmine.org/the-test/a-river-runs-though-it.jpg</url></item><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/mark-ruhi.jpg" /><url>http://headmine.org/the-test/mark-ruhi.jpg</url></item><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/mark.jpg" /><url>http://headmine.org/the-test/mark.jpg</url></item><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/namrok.jpg" /><url>http://headmine.org/the-test/namrok.jpg</url></item></channel></rss> Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974552 Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 Your markup looks fine, maybe your feedreader doesn't lie images? Quote Link to comment https://forums.phpfreaks.com/topic/184578-dynamic-array-using-glob/#findComment-974584 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.