472,960 Members | 2,045 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Help needed in displaying an image

GAR
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
Jul 17 '05 #1
1 2292
Hi Brian,

[SNIP]

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;
}

[/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_contents
etc.

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

Modify your code accordingly: -

[SNIP]

if( file_exists($album_cover_art) )
{
// check image type...might want to be able to use other image
types
header('content-type: ' .
image_type_to_mime_type(exif_imagetype($album_cove r_art)) );
readfile($album_cover_art);
}

[/SNIP]

Hope this will help..

-- Rahul

"GAR" <bb@spamsucks.com> wrote in message news:<BP*********************@newssrv26.news.prodi gy.com>...
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

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
2
by: Lyn | last post by:
Hi, I am struggling to display photographs in a list format. Any help will be greatly appreciated. Originally I had attempted to store photographs as embedded OLE Objects, but had lots of...
13
by: DavidS | last post by:
I have HTML web page with <asp:Image id=img_L runat=server ImageAlign=Top Visible=True Width=y Height=x></asp:Image>. For some images, less than 128K I can view image. Other image files > 128K,...
10
by: arun | last post by:
I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0. I would like to know how to make a color of my choice by specifying RGB values. Perhaps MSVC++, Dev- C++ have their own libraries...
5
by: Buchwald | last post by:
hello group, I have a long (large) script that shows a random picture when a webpage is refreshed. It's long because i have a lot of pictures: 246 Here is some code:...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
praclarush
by: praclarush | last post by:
I need to take an image that was in a Array object image and have it display in a table. this is for a item list the table has four columns one for the image, one for a description, one for a price,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.