473,503 Members | 10,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2317
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
2571
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
3464
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
1809
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
1330
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
2416
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
1199
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
5518
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
1894
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
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.