Except where otherwise noted, the contents of this document are Copyright © Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
thanks to former TAs Victoria Kirst, Jeff Prouty, Morgan Doocy, Brian Le for their work on these labs.
Brian has written a page named music.php
to display his MP3s.
He has already written the basic HTML and CSS code.
But the HTML is redundant, and he must manually edit it every time he adds songs to his collection.
In this lab, you will turn this page into a dynamic PHP page that removes redundancy and dynamically lists the MP3s on the computer. Download the file below to get started (right-click and Save As, or View Source):
Brian has 1234 songs (123 hours of music). Turn this into a PHP variable you can change.
music.php
and open it in your text editor.
music.php
online to see the change.
for
loop.
http://music.yahoo.com/videos/justin-bieber/
(See example screenshot on next slide.)
The page hard-codes the list of MP3 file names. Change it to read file names from the server.
/var/www/html/songs/
, or you can download them as
songs.zip.
.mp3
files in the /var/www/html/songs/
folder using the glob
function.
(Pass a folder/file path to glob
, NOT a URL. For debugging, you may want to print_r
the array.)
li
list item with the class
of mp3item
.
Your MP3 list should look like this when you are done:
(See example screenshot on next slide.)
Now let's format the MP3 links to look better.
.../songs/
folder.
basename
function to extract the file name from a larger path string. e.g. basename("a/b/c.txt")
returns "c.txt"
.
a
tag whose href
target is the same as the song file's full URL.)
filesize(filename)
function.
1 kb is 1024 bytes.
Your MP3 list should look like this when you are done:
(See example screenshot on next slide.)
Add code to display the contents of .m3u
playlists.
A playlist is just a text file containing a list of song file names, one per line.
It can also have comment lines that begin with #
. (You can ignore/skip comment lines.)
Example:
#EXTM3U #EXTINF:177,Paul Dateh & Oren Yoel - Be More be-more.mp3 #EXTINF:291,Christopher Toy - Just Because just-because.mp3
.m3u
files in the /var/www/html/songs/
directory, and for each one, displays a list of the playlist's songs as a nested list.
(Use a separate foreach
loop and glob
call after the one for the MP3 files.)
strpos
function to search a line for the index of a given substring.
Your page should look like this when you are done:
audio
tag: HTML5 includes a new audio
tag for playing sounds.
Modify the page to insert an audio
tag for each song so that it can be played in the page.
drift-away.mp3
) would go first and smallest songs (such as cse-154-rap.mp3
) last.
If you finish all the exercises, you can add any other content or code you like to your page.
If the lab is over or almost over, check with a TA and you may be able to be dismissed.
Great work!