471,596 Members | 818 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

automating current static page with 3 directory contents on the fly

Hi there,

I think it's best to explain things first.. (it's a sermons archive)
I manage a static page which I'd like to automate. This page is an archive that lists mp3s and their notes(pdf) as well as zip files. Every week i have to add two new mp3s and their pdf notes, remove entries and add a zip.
if you'd like to see what it looks like, to maybe understand me: http://www.eastside.org.za/index.php?pageid=1552

each file type is in a separate directory, ie: Sermon/mp3, Sermon/pdf, Sermon/zip. I dont have a database to make use of and because of this I'm not sure where to start. I did try with an array, but I got lost when things didnt work.

I would really appreciate someone pointing me in the right direction. It seemed rather easy when I started with just a directory listing, but when I put the list in an array and tried to extract the name of the sermon giver using split() and my brain going ahead of me thinking of ordering everything according to the date, I decided to ask for help.

I started with one directory to make things simpler for myself.
I dont code clean when I'm trying to figure things out. each time i try something new, I comment out what was tried. I know it is a mess, but as i said, i'm lost as to what i should do.

Here Is My Code (see results of code below):

Expand|Select|Wrap|Line Numbers
  1. <?php //http://www.eastside.org.za/index.php?page=newsermons
  2. /* PROJECT Begun On 18 April 2009
  3. DATE started: Sat 18 Apr 2009;
  4. TIME started: 10:00AM;
  5. DATE stopped: Sun 19 Apr 2009
  6. TIME stopped: 01:51AM;
  7. */
  8. //this is very much USELESS when i break it, as the php code is within a CMS - if something is wrong, I get a blank page :o(
  9. error_reporting(E_ALL);
  10. $dirname = "UserFiles/eastside.intoweb.co.za/Sermons/mp3";
  11. $dir = opendir( $dirname );
  12.         $mp3list2 = array();
  13.         $noddy = array();
  14.         $noddy2 = array();
  15.         $ff = 0;
  16.         $file_list = "";
  17.  
  18. while( false != ( $file = readdir( $dir ) ) ) {
  19.     if( ( $file!= "." ) and ( $file != ".." ) ) {
  20.         $file_list .= "<li>$file</li>";
  21.         //$mp3list = explode( " ", $file );
  22.         $mp3list = split( '[ .]', $file );
  23.         //THIS LINE v
  24.         array_push( $mp3list2, split( '[ .]', $file ) );
  25.         //array_push( $mp3list2, 'day' => array($mp3list[0]), 'month' => array($mp3list[1]), 'year' => array($mp3list[2]), 'time' => array($mp3list[3]), 'preach' => array($mp3list[4]), 'ext' => array($mp3list[5]) );
  26.         //THIS LINE v
  27.         //$mp3day = $mp3list[0]; $mp3month = $mp3list[1]; $mp3year = $mp3list[2]; $mp3time = $mp3list[3]; $mp3preach = $mp3list[4]; $mp3ext = $mp3list[5];
  28.         //AND THIS LINE TOO v 
  29.         //array_push( $mp3list2, 'day' => $mp3day, 'month' => $mp3month, 'year' => $mp3year, 'time' => $mp3time, 'preach' => $mp3preach, 'ext' => $mp3ext );
  30. /*
  31.         -catch all preachers with  element 4 into preacher array['nameofpreacher',$sermons];
  32.         -$sermons in each pastor = the sermons that that preacher gave;
  33.         -for every preacher in array, there will be their heading: Bruce, Riaan, Guest;
  34.         -under each heading a list of sermons given plus a link to their mp3
  35.         -- keeping in mind the sermon-notes associated with that sermon:
  36.         sermon1 - note1
  37.         sermon6 - note6
  38.         sermon4 - note4
  39. */
  40.         //I'm lost, so i'm just screwing around..
  41.         $noddy = array( list( $sday, $smonth, $syear, $stime, $spreach ) = split( '[ .]', $file ) );
  42.         list( $sday, $smonth, $syear, $stime, $spreach ) = split( '[ .]', $file );
  43.         if( $spreach == "Bruce" ) {
  44.             ////FREAK, i was so close, but array_push just doesnt work...
  45.             $noddy2 = array( "bruce" => array($sday, $smonth, $syear, $stime) );
  46.             //YES honey, array push doesnt work like above by just appending _push... ROTFLMAO
  47.             //so it broke
  48.             ///array_push( $noddy2, "bruce" => array($sday, $smonth, $syear, $stime ) );
  49.             //will this do it?
  50.             ///array_push( $noddy2, "bruce" => array( $ff => array($sday, $smonth, $syear, $stime ) ) );
  51.         } //and it didnt work BECAUSE of this - figures, it's AFTER 1AM!! 
  52.         $ff++;
  53.     }
  54. }
  55.  
  56. closedir( $dir );
  57.  
  58. //echo( "<title>$dirname</title>" );
  59. //echo( "<table><tr><td>$file_list</td><td>" );
  60. print_r( $mp3list );
  61. echo( "<br><br>" );
  62. print_r( $mp3list2 );
  63. //echo( "</td></tr></table>" );
  64. echo( "<br><h2>$mp3list[4]</h2>
  65. <a href='$dirname/$mp3list[0]%20$mp3list[1]%20$mp3list[2]%20$mp3list[3]%20$mp3list[4].$mp3list[5]'>
  66. $mp3list[0] $mp3list[1] $mp3list[2] $mp3list[3]</a>" );
  67.  
  68.         echo( "<br><hr> $sday, $smonth, $syear, $stime, $spreach<hr><br>" );
  69.         print_r( $noddy );
  70.         echo( "<hr><hr><br>" );
  71.         print_r( $noddy2 );
  72.         echo( "<hr><hr><br>" );
  73. echo( '<br><br>'.implode(" ", $mp3list2[5]) ); 
  74.  
  75. /*
  76. $pieces = explode(" ", $pizza);
  77. echo $pieces[0]; // piece1
  78. echo $pieces[1]; // piece2
  79.  
  80. Example 2
  81. $data = "foo:*:1023:1000::/home/foo:/bin/sh";
  82. list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
  83. echo $user; // foo
  84. echo $pass; // *
  85. // Delimiters may be slash, dot, or hyphen
  86. $date = "04/30/1973";
  87. list($month, $day, $year) = split('[/.-]', $date);
  88. echo "Month: $month; Day: $day; Year: $year<br />\n";
  89. */
  90. ?>
i'll keep playing(screwing) around, so if u wanna see if i have anything to show, have a look at the newsermons page. am i perhaps taking it from the wrong angle?

Thanks so much
SMiLE
Apr 19 '09 #1
3 1442
Atli
5,058 Expert 4TB
Hi.

The biggest problem with your layout is the file names. They are inconsistent.
You need to settle on a fixed format, so that you can easily parse them into useful pieces in your code.

Once you have done that, you can use the glob function to search for all the Mp3 files, and the file_exists function to make sure there is a PDF file that goes with it.

For example, if I assume a file structure like this:
Expand|Select|Wrap|Line Numbers
  1. sermons/
  2.     mp3/
  3.         John Doe_2009-04-19.mp3
  4.         John Doe_2009-03-12.mp3
  5.         John Johnsson_2008-02-30.mp3
  6.     pdf/
  7.         John Doe_2009-04-19.pdf
  8.         John Doe_2009-03-12.pdf
  9.         John Johnsson_2008-02-30.pdf
You could use the glob() function to search for all the Mp3 files, like so:
Expand|Select|Wrap|Line Numbers
  1. $mp3list = glob("sermons/mp3/*.mp3");
Then you would need to parse the file names into names and dates, check if the Mp3 has a matching PDF file, and save all that into an array so you can print it later.
Expand|Select|Wrap|Line Numbers
  1. $names = array();
  2. foreach($mp3list as $_mp3file) {
  3.     // Split the path into individual parts.
  4.     $parts = explode('/', $_mp3file);
  5.  
  6.     // This uses regular expressions to 
  7.     // split the file name on all dashes (-) and dots (.).
  8.     list($name, $date, $ext) = preg_split('/[_\.]/is', end($parts));
  9.  
  10.     // See if a PDF file exists
  11.     $pdfPath = "serms/pdf/{$name}_{$date}.pdf";
  12.     $pdfExists = file_exists($pdfPath);
  13.  
  14.     // Store the file in the $names array.
  15.     $names[$name][$date] = array(
  16.         'pdf' => $pdfExists
  17.     );       
  18. }
Now you got all the files in a nicely formatted array, so you can sort it and print it in whatever way you want.
For example:
Expand|Select|Wrap|Line Numbers
  1. // Go through the storage array and print every name
  2. foreach($names as $_name => $_dates) {
  3.     // Sort the dates
  4.     ksort($_dates);
  5.  
  6.     // Print the name
  7.     echo "<div><strong>{$_name}</strong><ul>";
  8.  
  9.     // Print each date, along with a link to the
  10.     // Mp3 and the PDF (if any)
  11.     foreach($_dates as $_date => $_values) {
  12.         echo "<li>{$_date}: ",
  13.              "<a href=\"serms/mp3/{$_name}_{$_date}.mp3\">Mp3</a>"; 
  14.         if($_values['pdf']) {
  15.             echo ", <a href=\"serms/pdf/{$_name}_{$_date}.pdf\">PDF</a>";
  16.         }
  17.     }
  18.  
  19.     // Print fotter
  20.     echo "</ul></div>";
  21. }
Which should print something like:
Expand|Select|Wrap|Line Numbers
  1. John Doe
  2.     * 2009-03-12: Mp3, PDF
  3.     * 2009-04-19: Mp3, PDF
  4.  
  5. John Johnsson
  6.     * 2008-02-30: Mp3, PDF
See what I mean?
Apr 19 '09 #2
@Atli
I know there is a BIG difference between the mp3 name and the pdf name.
Lucky for me, I'm the media and web guru for the church, so i can get a change..
The file structure for the mp3 is (in php date format), "d M Y A" followed by the speaker_surname.mp3, so "19 Apr 2009 AM Bruce.mp3"
for the moment the pdf has no logical structure : "name of sermon.pdf" - i'd like to follow the same structure as above, "19 Apr 2009 AM Bruce.pdf"
@Atli
note that sometimes they never provide notes
@Atli
should the filename rather be "19-Apr-2009_AM Bruce.mp3" so i can use regex, which i am SLOWLY learning in my job.
@Atli
I do, thanks. I also take it that if my name for the files are "d-M-Y_A speaker surname.mp3", I can parse the date into "d M Y morning" and it would look like:
Expand|Select|Wrap|Line Numbers
  1. Bruce
  2. 19 Apr 2009 morning (approx filesize)
  3.  
  4. Madame Surname
  5. 22 March 2009 evening (approx filesize)
  6.  
  7. Name Surname
  8. 22 March 2009 morning (approx filesize)
  9.  
  10. Riaan von Silly-surname
  11. 12 Apr 2009 morning (approx filesize) Notes
  12. 12 Apr 2009 evening (approx filesize) Notes
  13. 19 Apr 2009 evening (approx filesize) Notes
  14.  
noting that not everyone knows how to use capitals..when saving files...?!?
i know I'm a monkey when it comes to sorting, but I'll worry about that later.

thanks
ps. I'll try this new structure and all by touching files in a new directory ;o)
Apr 19 '09 #3
I did it!!

Thanks Alti (and Charl H from Intoweb), although I have a date sort problem in the dates of the zip files - dunno why :-( (I'd appreciate a hint ;-) )
Without your help I prolly would have taken the long, wrong route...

I know the code is messy, but I intend cleaning it up when the church is happy with the end result

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dirname = "UserFiles/eastside.intoweb.co.za/Sermons/mp3/";
  3. $dirname2 = "UserFiles/eastside.intoweb.co.za/Sermons/pdf/";
  4. $dirname3 = "UserFiles/eastside.intoweb.co.za/Sermons/doc/";
  5. $dirname4 = "UserFiles/eastside.intoweb.co.za/Sermons/zip/";
  6. $sizeDivider = 1024; // Divide fileSize by
  7. $sermonFiles = "";
  8. $sermonZips = "";
  9.  
  10. //$mp3list = glob("sermons/mp3/*.mp3");
  11. $mp3list = glob("$dirname*.mp3");
  12. /*$adate = array(
  13.     'jan' => '01',
  14.     'feb' => '02',
  15.     'mar' => '03',
  16.     'apr' => '04',
  17.     'may' => '05',
  18.     'jun' => '06',
  19.     'jul' => '07',
  20.     'aug' => '08',
  21.     'sep' => '09',
  22.     'oct' => '10',
  23.     'nov' => '11',
  24.     'dec' => '12'
  25. );*/
  26. $names = array();
  27. foreach($mp3list as $_mp3file) {
  28.     // Split the path into individual parts.
  29.     $parts = explode('/', $_mp3file);
  30. /*    $fpart = preg_split('/[_\.]/is', end($parts));
  31.     while (list($key, $val) = each($fpart)) {
  32.  
  33.         $udate = strtotime(substr($val, 0, 14));
  34.         print($udate);
  35.         //print_r("<BR>".$key." == ".$val."<br>");
  36.     }
  37.  */
  38.     // This uses regular expressions to 
  39.     // split the file name on all dashes (-) and dots (.).
  40.     list($date, $name, $ext) = preg_split('/[_\.]/is', end($parts));
  41.  
  42.     // See if a PDF file exists
  43.     $pdfPath = "$dirname2{$date}_{$name}.pdf";
  44.     $pdfExists = file_exists($pdfPath);
  45.  
  46.     // See if a DOC file exists
  47.     $docPath = "$dirname3{$date}_{$name}.doc";
  48.     $docExists = file_exists($docPath);
  49.  
  50.     // Turn $date into timestamp
  51.     $predate = substr($date, 0, 11);
  52.     $predate .= " ".substr($date, 12, 14);
  53.     //echo($predate);
  54.     $udate = strtotime($predate);
  55.     //echo("bob".$udate."pop<hr>"); 
  56.  
  57.     // Store the file in the $names array.
  58.     // Lets put timestamp in front of names?
  59.     $names[$udate][$name][$date] = array(
  60.         'pdf' => $pdfExists,
  61.         'doc' => $docExists
  62.     );   //^^^^^//, 'timestamp' => $udate 
  63. }
  64. //print_r($names);
  65. /* thanks Charl
  66. foreach($names as $name)
  67. {
  68.     ## ok so here we make the dates into timestamps
  69.     ## now you can put them into a array with the timestamp as the key and the values
  70.     ## will be the data then just use ksort
  71.  
  72.     while (list($key, $val) = each($name)) {
  73.  
  74.         $udate = strtotime(substr($key, 0, 11));
  75.         echo($udate);
  76.         print_r("<BR>".$key." ".$val."<br>");
  77.     }
  78.     print "-------<BR><BR>";
  79. }
  80. die();
  81. */ //PUT KSORT UP HERE noob
  82.     // Sort the dates
  83.     // sort da array by key
  84.     ksort($names);
  85. // Go through the storage array and print every name
  86. foreach($names as $_udate => $_name) {
  87. /* doesnt work    
  88.     foreach($_dates as $_date => $_values) {
  89.         ksort($_values['timestamp']);
  90.     }
  91. */
  92.     // Sort the names
  93.     // sort da array by value
  94.     //asort($names);
  95.     /*
  96.     echo("<br>_name: ");
  97.     print_r($_name);
  98.     echo("<BR");
  99.     */
  100.     // Print the name
  101.     //echo "<div>1st foreach<strong>{$_name[0]}</strong><ul>";
  102.     foreach($_name as $_names => $_dates) {
  103.  
  104.     // Print the name
  105.     //echo "<div>2nd foreach<strong>{$_names}</strong><ul>";
  106.     //echo "<div><strong>{$_names}</strong><ul>";
  107.     $sermonFiles .= "<span style=\"font-weight: bold; color: rgb(0, 0, 0); text-decoration: underline;\">{$_names}</span><br /><br />";
  108.  
  109.     // Print each date, along with a link to the
  110.     // Mp3 and the PDF (if any)
  111.     foreach($_dates as $_date => $_values) {
  112.  
  113.     // Print the name
  114.     //echo "<div>3rd foreach<strong>{$_names}</strong><ul>";
  115.         $dated = $_date;
  116.         /*
  117.         echo "<hr>";
  118.         print_r($_values);
  119.         */
  120.     // Somewhere prolly here, need to parse the date, extracting 04 and turning it into Apr
  121.         $dated = str_replace("-", " ",$dated);
  122.           $mp3Size = filesize("$dirname{$_date}_{$_names}.mp3");
  123.           //echo($mp3Size." ");
  124.           $mp3Size /= $sizeDivider; $mp3B = "KB";
  125.           if($mp3Size > 1024) { $mp3Size /= $sizeDivider; $mp3B = "MB"; }
  126.           //echo($mp3Size." ");
  127.           $mp3Size = round($mp3Size, 2);
  128.         //echo "<li>{$_date}: ",
  129.         //echo "<li>",
  130.         //     "<a href=\"$dirname{$_date}_{$_names}.mp3\">{$dated}.mp3</a> ({$mp3Size}{$mp3B})";
  131.         //$sermonFiles .= "<li>";
  132.         //unset($brBob);
  133.         $brBob = "0";
  134.         $sermonFiles .= "<a style=\"font-weight: bold; color: rgb(255, 255, 255);\" href=\"$dirname{$_date}_{$_names}.mp3\">{$dated}</a> ({$mp3Size}{$mp3B})"; 
  135.         if($_values['pdf']) {
  136.                 $brBob = "1";
  137.                 $pdfSize = filesize("$dirname2{$_date}_{$_names}.pdf");
  138.                   $pdfSize /= $sizeDivider; $pdfB = "KB";
  139.                   if($pdfSize > 100) { $pdfSize /= $sizeDivider; $pdfB = "MB"; }
  140.                   $pdfSize = round($pdfSize, 2);
  141.             //echo ", <a href=\"$dirname2{$_date}_{$_names}.pdf\">Notes</a> ({$pdfSize}{$pdfB})";
  142.             $sermonFiles .= " &nbsp; ";// Space between text and next text
  143.             $sermonFiles .= "<a style=\"font-weight: bold; color: rgb(255, 255, 255);\" href=\"$dirname2{$_date}_{$_names}.pdf\">Notes</a> ({$pdfSize}{$pdfB})<br />";
  144.         } 
  145.         if($_values['doc']) {
  146.                 $brBob = "1";
  147.                 $docSize = filesize("$dirname3{$_date}_{$_names}.doc");
  148.                   $docSize /= $sizeDivider; $docB = "KB";
  149.                   if($docSize > 100) { $docSize /= $sizeDivider; $docB = "MB"; }
  150.                   $docSize = round($docSize, 2);
  151.             //echo ", <a href=\"$dirname3{$_date}_{$_names}.doc\">Notes</a> ({$docSize}{$docB})";
  152.             $sermonFiles .= " &nbsp; ";// Space between text and next text
  153.                 $sermonFiles .= "<a style=\"font-weight: bold; color: rgb(255, 255, 255);\" href=\"$dirname3{$_date}_{$_names}.doc\">Notes</a> ({$docSize}{$docB})<br />";
  154.         } //echo($brBob."hhh ");
  155.         if(!$brBob) { $sermonFiles .= "<br />"; } 
  156.     }
  157.  
  158.     $sermonFiles .= "<br /><br />";
  159.     }
  160. }
  161.  
  162.  
  163. unset($date, $ext, $names, $parts, $udate);
  164. $names = array();
  165. $ziplist = glob("$dirname4*.zip");
  166. foreach($ziplist as $_zipfile) {
  167.     // Split the path into individual parts.
  168.     $parts = explode('/', $_zipfile);
  169.     // This uses regular expressions to 
  170.     // split the file name on all dashes (-) and dots (.).
  171.     list($series, $date, $ext) = preg_split('/[_\.]/is', end($parts));
  172.  
  173.     // Turn $date into timestamp
  174.     $udate = strtotime($date);
  175.     //echo("bob".$udate."pop<hr>"); 
  176.  
  177.     // Store the file in the $names array.
  178.     // Lets put timestamp in front of names?
  179.     $names[$udate][$series][$date] = array('fake' => 'nothing'); 
  180. }
  181. //print_r($names);die();
  182.     // Sort the dates
  183.     // sort da array by key
  184.     //ksort($names);
  185.     ksort($names);
  186. // Go through the storage array and print every name
  187. foreach($names as $_udate => $_serie) {
  188.  
  189.     foreach($_serie as $_series => $_dates) {
  190.     // Sort the dates
  191.     // sort da array by key
  192.     ksort($_serie);
  193.     //print_r($_serie);
  194.  
  195.     // Print each date
  196.     foreach($_dates as $_date => $_values) {
  197.  
  198.         $dated = $_date;
  199.     // Replace all "-" with " "
  200.         $dated = str_replace("-", " ",$dated);
  201.           $zipSize = filesize("$dirname4{$_series}_{$_date}.zip");
  202.           //echo($zipSize." ");
  203.           $zipSize /= $sizeDivider; $zipB = "KB";
  204.           if($zipSize > 100) { $zipSize /= $sizeDivider; $zipB = "MB"; }
  205.           //echo($zipSize." ");
  206.           $zipSize = round($zipSize, 2);
  207.         $sermonZips .= "<a style=\"font-weight: bold; color: rgb(255, 255, 255);\" href=\"$dirname4{$_series}_{$_date}.zip\">{$_series} ({$dated})</a> ({$zipSize}{$zipB})<br />"; 
  208.     }
  209.     }
  210. }
  211. $sermonZips .= "<br /><br />";
  212.  
  213.  
  214. echo("
  215.  
  216. <div style=\"padding-right: 10px; background-color: rgb(68, 164, 212);\">
  217.     <div style=\"font-weight: 700; color: rgb(255, 255, 255); text-align: right;\"><a style=\"font-weight: 700; color: rgb(255, 255, 255);\" href=\"javascript:history.back()\">Back to previous page</a></div>
  218.     <br />
  219.     <span style=\"font-weight: bold; color: rgb(255, 255, 255);\">SERMON ARCHIVE</span><br />
  220.     <span style=\"font-weight: bold;\"><br />
  221.         For any CD or print copies of sermons, please contact Carol at the Church office between 8am and 1pm.<br />
  222.         012 998 2877</span><br />
  223.     <a style=\"color: rgb(255, 255, 255); font-weight: bold;\" href=\"mailto:carol@eastside.org.za\">carol@eastside.org.za</a><br />
  224.     <br />
  225.     <table border=\"0\" width=\"100%\">
  226.         <tbody>
  227.             <tr>
  228.                 <td><span style=\"font-weight: bold; font-size: 20pt; color: rgb(255, 255, 255);\">MP3 DOWNLOADS:</span><br />
  229.                     </td>
  230.                 <td width=\"4%\"><br />
  231.                     </td>
  232.                 <td><span style=\"font-weight: bold; font-size: 20pt; color: rgb(255, 255, 255);\">ZIP DOWNLOADS:</span></td>
  233.             </tr>
  234.             <tr>
  235.                 <td colspan=\"3\"> Please right click on the relevant link and select \"save target as\" or \"save link as\" to download the desired audio / zip file.</td>
  236.             </tr>
  237.             <tr>
  238.                 <td valign=\"top\"><br />
  239.                         $sermonFiles
  240.                     </td>
  241.                 <td>&nbsp;<br />
  242.                     </td>
  243.                 <td valign=\"top\"><br />
  244.                     <br />
  245.                     <br />
  246.                     $sermonZips
  247.                     </td>
  248.             </tr>
  249.         </tbody>
  250.     </table>
  251.     <hr style=\"width: 100%; height: 2px;\" />
  252.     <br />
  253.     <span style=\"font-weight: bold;\">For any CD or print copies of sermons, please contact Carol at the Church office between 8am and 1pm.<br />
  254.         012 998 2877</span><br />
  255.     <a style=\"color: rgb(255, 255, 255); font-weight: bold;\" href=\"mailto:carol@eastside.org.za\">carol@eastside.org.za</a><br />
  256.     </div> </div>
  257. ");
  258.  
  259.  
  260. /*
  261. //original code by Alti on bytes.com:
  262. $mp3list = glob("sermons/mp3/*.mp3");
  263. $names = array();
  264. foreach($mp3list as $_mp3file) {
  265.     // Split the path into individual parts.
  266.     $parts = explode('/', $_mp3file);
  267.  
  268.     // This uses regular expressions to 
  269.     // split the file name on all dashes (-) and dots (.).
  270.     list($name, $date, $ext) = preg_split('/[_\.]/is', end($parts));
  271.  
  272.     // See if a PDF file exists
  273.     $pdfPath = "serms/pdf/{$name}_{$date}.pdf";
  274.     $pdfExists = file_exists($pdfPath);
  275.  
  276.     // Store the file in the $names array.
  277.     $names[$name][$date] = array(
  278.         'pdf' => $pdfExists
  279.     );       
  280. }
  281. // Go through the storage array and print every name
  282. foreach($names as $_name => $_dates) {
  283.     // Sort the dates
  284.     ksort($_dates);
  285.  
  286.     // Print the name
  287.     echo "<div><strong>{$_name}</strong><ul>";
  288.  
  289.     // Print each date, along with a link to the
  290.     // Mp3 and the PDF (if any)
  291.     foreach($_dates as $_date => $_values) {
  292.         echo "<li>{$_date}: ",
  293.              "<a href=\"serms/mp3/{$_name}_{$_date}.mp3\">Mp3</a>"; 
  294.         if($_values['pdf']) {
  295.             echo ", <a href=\"serms/pdf/{$_name}_{$_date}.pdf\">PDF</a>";
  296.         }
  297.     }
  298.  
  299.     // Print fotter
  300.     echo "</ul></div>";
  301. }
  302. */
  303. ?>
Apr 22 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Limey Drink | last post: by
2 posts views Thread by jordan | last post: by
6 posts views Thread by Charles Banas | last post: by
4 posts views Thread by James Johnson | last post: by
3 posts views Thread by Joseph S. | last post: by
2 posts views Thread by Dave | last post: by
6 posts views Thread by titan.nyquist | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.