audio-cast.php
· 1.3 KiB · PHP
原始文件
<?php
$YOUR_NAME = 'Melanie';
$WEBSITE_PATH = 'http://ds423/audio-cast';
$audioDirectory = '.';
$audioFiles = glob($audioDirectory . '/*.{mp3,m4a}', GLOB_BRACE);
usort($audioFiles, function ($a, $b) {
return filemtime($b) - filemtime($a);
});
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<rss version=\"2.0\" xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\">
<channel>
<title>{$YOUR_NAME}'s Audio Cast</title>
<link>{$WEBSITE_PATH}</link>
<description>Audio files in a folder as a podcast.</description>
<language>en-us</language>
";
foreach ($audioFiles as $audioFile) {
$title = pathinfo($audioFile, PATHINFO_FILENAME);
$extension = pathinfo($audioFile, PATHINFO_EXTENSION);
$pubDate = date(DATE_RSS, filemtime($audioFile));
$fileLink = $WEBSITE_PATH . "/" . rawurlencode($title) . "." . $extension;
$xml .=
"
<item>
<title>{$title}</title>
<link>{$fileLink}</link>
<description>{$title}</description>
<enclosure url=\"{$fileLink}\" length=\"" .
filesize($audioFile) .
"\" type=\"audio/mpeg\" />
<guid isPermaLink=\"false\">{$title}</guid>
<pubDate>{$pubDate}</pubDate>
</item>
";
}
$xml .= '
</channel>
</rss>
';
echo $xml;
?>
1 | <?php |
2 | |
3 | $YOUR_NAME = 'Melanie'; |
4 | $WEBSITE_PATH = 'http://ds423/audio-cast'; |
5 | |
6 | $audioDirectory = '.'; |
7 | |
8 | $audioFiles = glob($audioDirectory . '/*.{mp3,m4a}', GLOB_BRACE); |
9 | usort($audioFiles, function ($a, $b) { |
10 | return filemtime($b) - filemtime($a); |
11 | }); |
12 | |
13 | $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> |
14 | <rss version=\"2.0\" xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\"> |
15 | <channel> |
16 | <title>{$YOUR_NAME}'s Audio Cast</title> |
17 | <link>{$WEBSITE_PATH}</link> |
18 | <description>Audio files in a folder as a podcast.</description> |
19 | <language>en-us</language> |
20 | "; |
21 | |
22 | foreach ($audioFiles as $audioFile) { |
23 | $title = pathinfo($audioFile, PATHINFO_FILENAME); |
24 | $extension = pathinfo($audioFile, PATHINFO_EXTENSION); |
25 | $pubDate = date(DATE_RSS, filemtime($audioFile)); |
26 | $fileLink = $WEBSITE_PATH . "/" . rawurlencode($title) . "." . $extension; |
27 | |
28 | $xml .= |
29 | " |
30 | <item> |
31 | <title>{$title}</title> |
32 | <link>{$fileLink}</link> |
33 | <description>{$title}</description> |
34 | <enclosure url=\"{$fileLink}\" length=\"" . |
35 | filesize($audioFile) . |
36 | "\" type=\"audio/mpeg\" /> |
37 | <guid isPermaLink=\"false\">{$title}</guid> |
38 | <pubDate>{$pubDate}</pubDate> |
39 | </item> |
40 | "; |
41 | } |
42 | |
43 | $xml .= ' |
44 | </channel> |
45 | </rss> |
46 | '; |
47 | |
48 | echo $xml; |
49 | ?> |
50 |