I recently set up ampache so I can have an mp3 server. I dont like how
they display album covers so I decided to try and change it a little.
Instead of taking the album cover from the mp3s themselves I want it to just
have a file called 'cover.jpg' in the album's direcory where when someone
looks at the album the web browser will display that pic.
Here is what I have so far...
In the template:
<img src="albumart.php?id=<?=$album?>" alt="Album Art" align=right>
In albumart.php:
....
$album_name = get_album_name($_REQUEST['id']);
$songs = get_songs_from_album($_REQUEST['id']);
$full_filename = $songs[1]->file;
preg_match("/^.*\/(.*?)$/",$songs[1]->file, $filename);
// Get directory name.
$searchvalue = "/" . $filename[1] . "/";
$directory = preg_replace($searchvalue, "", $full_filename);
// Check if cover.jpg is in directory with album...
// Assumes all files from same album are in the same directory!!
$album_cover_art = $directory . "cover.jpg";
if( file_exists($album_cover_art) ){
// check image type...might want to be able to use other image types
header('content-type: ' . exif_imagetype($album_cover_art) );
echo $album_cover_art;
} else { //check in mp3s
....
What I'm trying to do here is I get the file location from the song and from
there I replace the song name with 'cover.jpg'. I then send it through the
if statement where if it finds the file in the albums directory I use that
file for the cover art otherwise it checks to see if the cover art is
included in the id3 tag (which is what it did before). Im pretty sure my
problem is in the if statement. Im not really sure how to send the pic back
to the browser.
Im pretty new to php so I'd appreciate it if anyone could help me out...
Thanks,
Brian