tags:

views:

84

answers:

4

Hello all,

I have the following:

$imageurl = "<img class='item_thumb'
src='getimagethumbnail.php?imagename=".urlencode($product_image)."&from=".$prodimagedir."' 
min-width='150' min-height='150' border='0' class='item_thumb'>";

Which creates the following html:

<img class="item_thumb" border="0" min-height="150" min-width="150"
src="getimagethumbnail.php?imagename=productsmall_1248886833bloggingbok.jpg&
from=products/"/>

However, the image does not show up. I point my browser to that src link and it gives me a bunch of unreadable text which I am assuming is the image meaning that the script getimagethumbnail is working fine. (I am guessing).

But as I said, the image is not appearing at all. What is wrong and what steps can I take to determine the problem?

Just to add, when I point my browser to that src link: It also gives me:

 Warning: Cannot modify header information - headers already sent by 
(output started at /home/dji/public_html/getimagethumbnail.php:35) in 
/home/dji/public_html/includes/functions.php on line 4953

I am assume this is because of the output?? This script was working fine and I have made no changes to it as far as I am aware!

Thanks

A: 

That error is caused when you print stuff to the output and then attempt to use the header() method. You shouldn't be outputting anything until after you do what you need with header(). Nothing should precede this, not even white-space.

Jonathan Sampson
+5  A: 

You are trying to send the header('Content-Type') command, after outputting whitespace/characters.

You need to make sure that the header command is before anything is printed on the page.

This will work:

 header('Content-Type: ....');
 readfile('file.png');

This won't

 readfile('file.png');
 header('Content-Type: ....');

This is because the header command tells the browser what to look for in the content. All of the headers must be sent before any content because that is how the connections works. The browser can't be told what to expect after the content has already been sent.

Open Connection With Server -> Get Headers -> Get Content -> Close Connection

One of the big reasons behind this is encoding. As the content comes through, the browser has to decode it properly. If you send a header in the middle of the page telling the browser that the encoding type is a, when it was processing it like b, things can get really confusing.

So, in order to send the headers properly, you must put the header command before any output.

Chacha102
Genius! That worked like a charm! No idea how that was missing. :)
Abs
A: 

You already have produced some output (on line 35) before setting the header for the image type. This might simply be a whitespace between php tags, or something you forgot to remove.

Zed
A: 

Your getimagethumbnail.php script is not generating a valid image; it's including text in it (the warning message you quote), which prevents browsers from rendering it. Judging by the error text, I'd guess this is due to changes made either to getimagethumbnail.php or functions.php.

Fundamentally, the problem is that functions.php is attempting to call header() after output has already been sent to the browser, which just plain won't work. You need to check both files and make sure that any calls to header() come before anything else that sends data to the browser.

You may want to turn off the display_errors setting, as any code which generates any warning or error for any reason will cause the problem you're seeing if the warning/error occurs before your header() calls. (Just make sure you have error logging on, so you can still see what's going wrong!)

Ben Blank