Yes, the problem was solved, but It did not work fine when I used the same code in my larger file. Now it makes sense. Let me just repeat what you have said just to make sure that I did not misread you. So you say that the solution to this problem is to create another php file with the image fetching header and just write an img tag <img src="myimagescript.php?id=1234" /> in my original php file (with the html tags). This is what I have understood. Regarding the point you have mentioned ( If you set the content type using header() to "image/jpeg", do not use HTML tags to display your image!), I definitely need the HTML tags, because this application works based on the user input. So unless there is not input through a html form, it wont work.

On Mon, Mar 9, 2009 at 1:29 AM, Sashikanth Gurram <sashi...@vt.edu> wrote:
Hi Nathan,

Thanks a lot for the suggestion. It is working fine for an example code I
have used to test it. The code I have written after your suggestion is as
header('Content-Type: image/jpeg');
The above code is yielding me a picture. Now, When I tried to use it in my
original code it is not giving me the image. Instead it is giving me this
warning *Warning*: Cannot modify header information - headers already sent
by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php*
on line *221*
and a lot binary characters again instead of the image. I know something
about this warning that we should not output anything to the browser before
the header. But I cannot do that, since I need the user input using a html
form and I use the input to fetch the data and dispaly it in a table along
with the image. I am posting the whole code below. Please do let me know
about any changes, corrections or modifications that are needed. The image
display code is towards the last.


<form action="mysqli.php" method="post">
<div align="center">
Building Name:<select name="name">
<option value=""> Select a Building</option>
    <option value="Williams Hall">Williams Hall</option>
    <option value="Women's Softball Field">Women's Softball Field</option>
    <option value="Wright House">Wright House</option>
                  <input type="submit" />
// Connects to your Database
$cxn=mysqli_connect($host, $user, $password, $dbname) ;
if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
      echo "$error";
      echo "Connection established successfully";
//Define the variables for Day and Month
if ($minute>=00 && $minute<=14)
elseif ($minute>=15 && $minute<=29)
elseif ($minute>=30 && $minute<=44)
$sql="SELECT buildingname, parking_lot_name, empty_spaces, distance,
round(distance/($low_speed*60),1) AS low_time,
round(distance/($high_speed*60),1) AS high_time, Location FROM buildings,
buildings_lots, parkinglots, occupancy2, Image where
(buildings.buildingcode=occupancy2.building AND
 buildings.buildingcode=buildings_lots.building_code AND
parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND
parkinglots.parking_lot_code=occupancy2.parking_lot AND
Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND
month='$Month' AND day='Monday' AND Time='$times'";
$data = mysqli_query($cxn,$sql);
if (!$data=mysqli_query($cxn,$sql))
      echo "$error";
      echo "<br>";
      echo "Query sent successfully";
echo "<br>";
echo "<table border='1' cellspacing='5' cellpadding='2'>";
echo "<tr>\n
      <th>Parking Lot</th>\n
      <th>Estimated Number of Empty Spaces</th>\n
      <th>Distance (Feet)</th>\n
      <th>Estimated walking time to the building</th>\n
while ($row=mysqli_fetch_array($data))
$building = $row[0];
    $parking_lot = $row[1];
    $Number_of_Empty_Spaces = $row[2];
    $Distance = $row[3];
    $time_l = $row[4];
    $location=$row[6];   echo "<tr>\n
            <td>$time_h - $time_l mins</td>\n
  echo "</table>\n";
header('Content-Type: image/jpeg');
Nathan Nobbe wrote:
On Sat, Mar 7, 2009 at 9:36 PM, Sashikanth Gurram <sashi...@vt.edu> wrote:

The thing is, I do not have a website or a place where I am storing my
images. I am storing the images on my local PC in folder as mentioned in
earlier post. I have tried using only the

else {
header('Content-Type: image/jpeg');

Which you have suggested. This is the piece of code which is returning
the binary character stuff. The code is definitely fetching the image.
it is not able to deliver to the browser in the form of an image. I am
trying to read the image file as binary, evident from the FILE_BINARY
command. So may be, that is causing the image to be displayed as binary.
there any way we can convert the binary content to jpeg/jpg content
This is my guess after having gone through the code again.

i spent 2 minutes working on it and read this in the manual,

the first param of imagejpeg(),

An image resource, returned by one of the image creation functions, such


so, then i tossed this together,


header('Content-Type: image/jpeg');

I see this one has already been solved, but I felt like I needed to
point this out: If you set the content type using header() to
"image/jpeg", do not use HTML tags to display your image! The expected
output is the actual binary data from the image, not an <img
src="asdf" /> tag. The OUTPUT of this script could be used in an IMG
tag elsewhere, perhaps, like so:

<img src="myimagescript.php?id=1234" />

Where "myimagescript.php" uses the Content-type header() and outputs
the binary JPEG data. If you were using PHP to build a javascript file
to be included, you wouldn't wrap it in <script> tags, either. Same
principle applies here.


Sashikanth Gurram
Graduate Research Assistant
Department of Civil and Environmental Engineering
Virginia Tech
Blacksburg, VA 24060, USA

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to