Part 5: Throwing It In
Open up "podcasting.php" for editing. This one DOES have to be a PHP page. This page is going to insert the new stuff into the database, then use all the
info in the database to remake the XML file. The explanation for this file goes line by line, the explanation follows right along with the blank lines in
the file.
podcasting.php
Connect to the database.
The date format that iTunes uses is put into the $dating variable.
The new info is put into the database.
Tell where the file is, then open up the file. The "w" in the function opens the file, then deletes all the information in it.
Here, the $info variable has all the information for the beginning of the Podcast. By reading through the code, you can probably guess what you need to
change. Do not change the first four lines. Don't forget you have to escape the quotes, as this is a string.
Write that info to the file.
Now, get the variables from the database to write the items in the Podcast.
Set the $info variable to the specifics of Podcasting and your database items. Since it's in the while statement, it'll keep writing until there's
nothing left in the database. You won't want to change these lines.
Write it, then continue the while loop until it's done.
Set the $info variable one last time to the closing tags, then write it. You won't want to change this either.
Close the file, then close the database.
<?php
$connection = mysql_connect("localhost", "pod_caster", "password");
mysql_select_db("user_site");
$dating = date("D, j F Y");
mysql_query("INSERT INTO `site_podcast` ( `id` , `title` , `author` , `subtitle` , `summary` , `url` , `date` , `duration`)
VALUES (
'', '$_POST[title]', '$_POST[author]', '$_POST[subtitle]', '$_POST[summary]', '$_POST[url]', '$dating', '$_POST[duration]'
);");
$file = "../podcast.xml";
$handle = fopen($file, 'w');
$info = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss xmlns:itunes=\"http://www.itunes.com/dtds/
podcast-1.0.dtd\" version=\"2.0\">
<channel>
<ttl>60</ttl>
<title>My Podcast</title>
<link>http://www.site.com/podcast/</link>
<language>en-us</language>
<copyright>No copyright</copyright>
<itunes:subtitle>Here's a subtitle.</itunes:subtitle>
<itunes:author>Author</itunes:author>
<itunes:summary>
This is so a summary that pops up if the i button is pushed.
</itunes:summary>
<description>
This is a description.
</description>
<itunes:owner>
<itunes:name>Name</itunes:name>
<itunes:email>email@somewhere.com</itunes:
email>
</itunes:owner>
<itunes:image href=\"http://www.site.com/images/podcast.
jpg\" />
<itunes:category text=\"Comedy\" />
";
fwrite($handle, $info);
$queryPod = mysql_query("SELECT * FROM site_podcast ORDER BY id ASC");
while($row = mysql_fetch_array($queryPod)) {
$title = $row['title'];
$author = $row['author'];
$subtitle = $row['subtitle'];
$summary = $row['summary'];
$url = $row['url'];
$date = $row['date'];
$duration = $row['duration'];
$info = " <item>
<title>$title</title>
<itunes:author>$author</itunes:author>
<itunes:subtitle>$subtitle</itunes:subtitl
e>
<itunes:summary>
$summary
</itunes:summary>
<enclosure url=\"$url\" />
<guid>
$url
</guid>
<pubDate>$date</pubDate>
<itunes:duration>$duration</itunes:duratio
n>
<itunes:keywords>
Keywords
</itunes:keywords>
</item>
";
fwrite($handle, $info);
}
$info = " </channel>
</rss>";
fwrite($handle, $info);
fclose($handle);
mysql_close($connection);
?>
Part 6: The Conclusion
Now, that was painless, right? Now you can have your own Podcast. Just a few things about Podcasting before I let you go.
To subscribe to a Podcast, open up iTunes and click the Advanced menu. Click the "Subscribe to Podcast" button. Enter the URL to your "podcast.xml".
In order to submit your Podcast to the iTunes Podcast Directory, you'll need an Apple account. If you have one, go to the Podcast Directory, then click
the "Submit a Podcast" link.
Remember, you can't use media types that iTunes can't read in a Podcast. That means no Windows type files.
That should be it. Hope you enjoyed the tutorial!