kirks Posted June 28, 2008 Share Posted June 28, 2008 I can easily write a php script to output XML from my mySQL database. However, podcast aggregators need the file to end with the XML extension. How do I get my php script to write the results to an external file with the XML extension? Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/ Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 Is this what you mean or have I misunderstood you? $f = fopen("path/somefile.xml", "w"); if ($f) { fwrite($f, $fileContents); $f = fclose($f); } Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/#findComment-576682 Share on other sites More sharing options...
kirks Posted June 28, 2008 Author Share Posted June 28, 2008 I'm not sure. I'm a newbie at best. Anyway, I want the code that's echoed below to be written to an xml file named path/mypodcast.xml: <?php //load database source files require("../scripts/webcasts.globals.php"); require("../scripts/webcasts.opendb.php"); // Perform database query $result = mysql_query("SELECT *, date_format(d_Date, '%a. %b %d, %Y') AS date, date_format(d_Date, '%a. ') AS day, date_format(t_Time, '%h:%i') AS time FROM tblWebcasts WHERE i_Id = 1", $connection); if(!$result) { die("Database query failed. Please report this error to web site administrator"); } echo ("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"); echo ("<rss>\n"); echo (" <channel>\n"); echo (" <title>" . $line['c_Title'] . "</title>\n"); echo (" <description>My description here</description>\n"); echo (" <link>http://www.mydomain.com</link>\n"); echo (" <category domain=\"\">Religion & Spirituality:Christianity</category>\n"); echo (" <copyright>©Copyright name of entity. All Rights Reserved.</copyright>\n"); echo (" <language>en-us</language>\n"); echo (" <lastBuildDate>" . $line['date'] . "</lastBuildDate>\n"); echo (" <managingEditor>[email protected]</managingEditor>\n"); echo (" <pubDate>" . $line['date'] . "</pubDate>\n"); echo (" <generator></generator>\n"); echo (" <item>\n"); echo (" <title>" . $line['c_Title'] . "</title>\n"); echo (" <description>description here</description>\n"); echo (" <link>http://www.mydomain.com/" . $line['c_Filename'] . "</link>\n"); echo (" <category domain=\"\">Religion & Spirituality:Christianity</category>\n"); echo (" <enclosure url=\"http://www.mydomain.com" . $line['c_Filename'] . "\" length=\"19409371\" type=\"audio/mpeg\"/>\n"); echo (" <guid isPermaLink=\"false\">CF1BC542-D123-47B9-8FA8-023A63B719F1</guid>\n"); echo (" <pubDate>" . $line['date'] . "</pubDate>\n"); echo (" </item>\n"); echo (" </channel>\n"); echo ("</rss>\n"); //close database connection require("../scripts/webcasts.closedb.php"); ?> Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/#findComment-576764 Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 This would work but if not let me know and I'll take another look. (I haven't been able to test it as I'm about to go out!) <?php //load database source files require("../scripts/webcasts.globals.php"); require("../scripts/webcasts.opendb.php"); // Perform database query $result = mysql_query("SELECT *, date_format(d_Date, '%a. %b %d, %Y') AS date, date_format(d_Date, '%a. ') AS day, date_format(t_Time, '%h:%i') AS time FROM tblWebcasts WHERE i_Id = 1", $connection); if(!$result) { die("Database query failed. Please report this error to web site administrator"); } $buff = "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"; $buff .= "<rss>\n"; $buff .= " <channel>\n"; $buff .= " <title>" . $line['c_Title'] . "</title>\n"; $buff .= " <description>My description here</description>\n"; $buff .= " <link>http://www.mydomain.com</link>\n"; $buff .= " <category domain=\"\">Religion & Spirituality:Christianity</category>\n"; $buff .= " <copyright>©Copyright name of entity. All Rights Reserved.</copyright>\n"; $buff .= " <language>en-us</language>\n"; $buff .= " <lastBuildDate>" . $line['date'] . "</lastBuildDate>\n"; $buff .= " <managingEditor>[email protected]</managingEditor>\n"; $buff .= " <pubDate>" . $line['date'] . "</pubDate>\n"; $buff .= " <generator></generator>\n"; $buff .= " <item>\n"; $buff .= " <title>" . $line['c_Title'] . "</title>\n"; $buff .= " <description>description here</description>\n"; $buff .= " <link>http://www.mydomain.com/" . $line['c_Filename'] . "</link>\n"; $buff .= " <category domain=\"\">Religion & Spirituality:Christianity</category>\n"; $buff .= " <enclosure url=\"http://www.mydomain.com" . $line['c_Filename'] . "\" length=\"19409371\" type=\"audio/mpeg\"/>\n"; $buff .= " <guid isPermaLink=\"false\">CF1BC542-D123-47B9-8FA8-023A63B719F1</guid>\n"; $buff .= " <pubDate>" . $line['date'] . "</pubDate>\n"; $buff .= " </item>\n"; $buff .= " </channel>\n"; $buff .= "</rss>\n"; $f = fopen("path/somefile.xml", "w"); if ($f) { fwrite($f, $buff); $f = fclose($f); } //close database connection require("../scripts/webcasts.closedb.php"); ?> Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/#findComment-576796 Share on other sites More sharing options...
LemonInflux Posted June 28, 2008 Share Posted June 28, 2008 Or just use .htaccess..? ---------------- Now playing: Flyleaf - All Around Me via FoxyTunes Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/#findComment-576848 Share on other sites More sharing options...
kirks Posted June 28, 2008 Author Share Posted June 28, 2008 I just realized that my hosting company will NOT allow a script to write to a file in the public web space because of security reasons. So ... Thanks any way. ks Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/#findComment-576864 Share on other sites More sharing options...
LemonInflux Posted June 28, 2008 Share Posted June 28, 2008 Or just use .htaccess..? ---------------- Now playing: Enter Shikari - Mothership via FoxyTunes Link to comment https://forums.phpfreaks.com/topic/112325-podcast-xml-file/#findComment-576874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.