473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Getting error when outputting image using headers. (Solution)

n8kindt
221 100+
i just spent nearly 3hrs trying to debug this problem so i figured i would post this just in case someone else has the same problem in the future. if you're trying to output binary data as an image in php and getting an error message like this: "the image [ ] could not be displayed because it contains errors" or a broken image red box looking thingie then check this out.

this code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header('Content-type: image/jpeg');
  3. include $_SERVER['DOCUMENT_ROOT'].'/includes/globals.php';
  4. $db_con = open_db();
  5.  
  6.         $image_q = 'SELECT `image` FROM `fc_pix`';
  7.         $image_r = mysql_query($image_q);
  8.         while ($image_w = mysql_fetch_array($image_r)){
  9.         echo $image_w['image'];
  10.         }
  11.     close_db($db_con)
  12. ?>
  13.  
IS NOT THE SAME AS:

Expand|Select|Wrap|Line Numbers
  1.  
  2. (*********pretend this is a blank line***********)
  3. <?php
  4. include $_SERVER['DOCUMENT_ROOT'].'/includes/globals.php
  5. header('Content-type: image/jpeg');
  6. $db_con = open_db();
  7.  
  8.         $image_q = 'SELECT `image` FROM `fc_pix`';
  9.         $image_r = mysql_query($image_q);
  10.         while ($image_w = mysql_fetch_array($image_r)){
  11.         echo $image_w['image'];
  12.         }
  13.     close_db($db_con)
  14. ?>
  15.  
that blank line at the top will throw the image parsing off completely and even though by all appearances all the data is being output correctly, that extra line gap will not allow it to be read. just thought i'd post this b/c when i searched google i found a lot of people had this problem and ultimately never figured it out.
Sep 17 '08 #1
1 1432
Markus
6,050 Expert 4TB
FYI: That is because when you use header()s, there can be no output whatsoever before the headers are sent. You'll receive an 'headers already sent' error.

Cheers.

PS: Please provide more meaningful post names when posting. I have changed yours for you.

Moderator
Sep 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: kingofkolt | last post by:
im trying to let a user download a file from my website, for example a picture. i dont want the user to have to right-click and do save-as, but instead i want a window to popup (the window with...
5
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
4
by: Jonathan | last post by:
I have a client solution that requires data and associated files to be stored with data in a database. As such, I have a situation where JPEG thumbnails/images that are stored as BLOBs (image...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
0
by: Chris Morse | last post by:
Hi, I am creating a solution with two projects. Basically, they share a few common class files and forms. I finished one project, and it compiles and runs fine. I just finished bringing in...
0
by: Mufasa | last post by:
I've got a browser object ( the standard one in VS ) that plays assorted stuff. When it goes to a specific website, I'm getting the following error: While attemping to set Frame A on machine...
0
by: Adamn | last post by:
Hi everybody! I'm using Visual Studio 2005 and don't know how to solve this problem. Till now, everything worked just fine, included all the necessary libs, headers and so on. But there is the...
32
by: C. (http://symcbean.blogspot.com/) | last post by:
Hi all, I have an application which generates image graphs. These cache nicely at the client, however if the user submits more data, I'd like to force a reload of the image from the server. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.