00:00
00:00
Newgrounds Background Image Theme

Breakfast-Crow just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php: Mysql, Php, And Podcasting

3,073 Views | 5 Replies
New Topic Respond to this Topic

Php: Mysql, Php, And Podcasting 2006-08-01 03:01:39


PHP: Main

MySQL, PHP, and Podcasting

Part 1: The Introduction
Now, there is an RSS tutorial already in PHP: Main, but this is alot different. You see, I don't like the idea of having an XML page be in PHP. I figure

that it should be a static page.

I started a Podcast a little while ago, just to see how it would be. It's pretty cool, I must say, just to say that you have a Podcast. I've been trying

for quite a while now to figure out a good way to make it dynamic, without it being a .php file. That's when I tried working with the file

functions. I've decided that I love them, and that they are the best way to do it.

To start, I'd like to say that my host does not currently support PHP 5, so you may notice some of my code to be a little...outdated. For instance, I

will use fopen(), fwrite(),

and fclose(), instead of just calling to file_put_contents(), as that last function is not supported by PHP 4.

Alright, let's begin, shall we?

Part 2: Podcasting, Generally Speaking
Just a quick overview of what Podcasting is, in case you didn't know. Podcasting is accessable through iTunes. It's a place to get free music and movies

from other people. For instance, Homestarrunner.com has a Podcast, and so does Happy Tree Friends. They have mp4's of their cartoons you can download,

made specifically for your iPod. I on the other hand have an audio Podcast, which can be used on your iPod or just in iTunes.

Podcasting goes through an XML file. Some of the tags are iTunes specific, but it will be obvious which ones. I'll be giving you all the code you need to

create one.

Part 3: In The Beginning...
First off, let's create the files, just for kicks and giggles.

Number one, create a file named "podcast.xml", or named different if you want. I'll be using that filename for all intents and purposes. CHMOD it to 777.
Number two, create a file named "podcast.php", preferrably in a directory protected by HTACCESS below the directory that contains "podcast.xml".
Number three, create a file named "podcasting.php", in the same directory as "podcast.php".

Now, create the MySQL database. For this tutorial, I'll use the database name "user_site" and the username "pod_caster". If you don't know how to set up

the database...well, I'll let you figure that one out on your own.
The table name in this tut is going to be "site_podcast". You'll want to create yours and give it 8 fields. The first is "id"; make it key, make it INT,

and make it auto-increment. The rest are just going to be text - "title", "author", "subtitle", "summary", "url", "date", and "duration".

Kay, let's get coding.

Part 4: Throwing It Out
Open up your "podcast.php" for editing. Now, just so you know, this doesn't have to be a PHP page, but I have a few includes in mine, so I made it that

way. Oh, and this is my tutorial, so I can do whatever I want.

Now, I'm just gonna give the form code, nothing else. Very bare-bones and customisable.

podcast.php
<form action="podcasting.php" method="post">
Title: <input type="text" name="title" size="20" />
<br />
Author: <input type="text" name="author" size="20" />
<br />
Summary: <input type="text" name="summary" size="20" />
<br />
Subtitle: <input type="text" name="subtitle" size="20" />
<br />
URL: <input type="text" name="url" size="20" />
<br />
Duration (in X:XX format): <input type="text" name="duration" size="20" />
<br />
<input type="submit" value="Submit" />
</form>

Response to Php: Mysql, Php, And Podcasting 2006-08-01 03:02:43


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!

Response to Php: Mysql, Php, And Podcasting 2006-08-01 04:05:15


Nice tutorial, well explained.

I won't be making podcasts any time soon though :(

Response to Php: Mysql, Php, And Podcasting 2006-08-01 04:19:50


Very nice tutorial =)
I tried making podcast once, but realised i sounded like a twat when recording it.
Ah well...


|| Portfolio || Facebook || Twitter ||

BBS Signature

Response to Php: Mysql, Php, And Podcasting 2006-08-01 04:29:21


At 8/1/06 04:19 AM, DannyIsOnFire wrote: I tried making podcast once, but realised i sounded like a twat when recording it.

Mine sounds like crap, and I still wuv it :P

Response to Php: Mysql, Php, And Podcasting 2006-08-01 18:13:12


At 8/1/06 04:56 PM, Plakat wrote: Where is it? Didn't find it on your site.

http://www.woogienoogie.com/podcast/

I never really linked to it...I finally got it submitted to the directory, though :)