473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting error when outputting image using headers. (Solution)

n8kindt
221 New Member
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 1463
Markus
6,050 Recognized Expert Expert
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
1836
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 "Save File","Open File","More Info",etc) so that the user can download it easily. i have a feeling this has something to do with headers, but i have no idea what the correct headers are. thanks in advance - JP
5
2543
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 started sending out the content of the page. Web content is always delivered with a few headers at the top, ending with a blank line. For example, a web page might start like this:
67
4288
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. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
4
1824
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 data-type) in a SQL DB need to be written to an ASP.NET page. The BLOB is actually wrapped by a class written in C#, BlobObj, which can return a byte-array containing the image-bytes. I can successfully write the image to the page using the...
3
2795
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 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +201 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +263
0
1570
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 the second project, and I get the following error on one of the forms when it is invoked: ----------------------------------------------------------------- An unhandled exception of type
0
2182
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 ECS2059421 to 'http://image.weather.com/looper/archive/us_radar_plus_usen/2L.jpg?1176238592046' got an error. Error Type: System.Runtime.InteropServices.COMException Error Message: The requested resource is in use. (Exception from HRESULT:...
0
1229
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 problem: I have to implement a class ColorSpaces with static member functions, which manipulates a buffer from the class MSImage and returns it. ColorSpaces.h looks like this: class ColorSpaces { public:
32
3144
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 had a google, but all I could find were suggestions to use a varying query in the URL. This is not a solution to my problem because if I change the page to do that then ALL the graphs will be reloaded every time.
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.