Help needed in displaying an image

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GAR

    Help needed in displaying an image

    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.p hp?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($s earchvalue, "", $full_filename) ;

    // Check if cover.jpg is in directory with album...
    // Assumes all files from same album are in the same directory!!
    $album_cover_ar t = $directory . "cover.jpg" ;
    if( file_exists($al bum_cover_art) ){
    // check image type...might want to be able to use other image types
    header('content-type: ' . exif_imagetype( $album_cover_ar t) );
    echo $album_cover_ar t;
    } 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


  • Rahul Anand

    #2
    Re: Help needed in displaying an image

    Hi Brian,

    [SNIP]

    if( file_exists($al bum_cover_art) )
    {
    // check image type...might want to be able to use other image
    types
    header('content-type: ' . exif_imagetype( $album_cover_ar t) );
    echo $album_cover_ar t;
    }

    [/SNIP]

    In your code you are trying to output a file contents with an echo
    statement.
    But echo statement will only ouput the filename in this case. You file
    handling function to read and output the contents of a file.
    Few such functions are fread, fpassthru, readfile, file_get_conten ts
    etc.

    Another thing exif_imagetype function returns an INTEGER constant you
    need to convert this value to appropriate mime type. Function
    image_type_to_m ime_type will do that.

    Modify your code accordingly: -

    [SNIP]

    if( file_exists($al bum_cover_art) )
    {
    // check image type...might want to be able to use other image
    types
    header('content-type: ' .
    image_type_to_m ime_type(exif_i magetype($album _cover_art)) );
    readfile($album _cover_art);
    }

    [/SNIP]

    Hope this will help..

    -- Rahul





    "GAR" <bb@spamsucks.c om> wrote in message news:<BPNDb.127 50$aw2.6812542@ newssrv26.news. prodigy.com>...[color=blue]
    > 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.p hp?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($s earchvalue, "", $full_filename) ;
    >
    > // Check if cover.jpg is in directory with album...
    > // Assumes all files from same album are in the same directory!!
    > $album_cover_ar t = $directory . "cover.jpg" ;
    > if( file_exists($al bum_cover_art) ){
    > // check image type...might want to be able to use other image types
    > header('content-type: ' . exif_imagetype( $album_cover_ar t) );
    > echo $album_cover_ar t;
    > } 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[/color]

    Comment

    Working...