Re: Retrieving Image Location in MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I have tried it in 3 browsers (Chrome, firefox and internet explorer) and none of them has given me any image.
-Sashi

Phpster
wrote:
Bet the image is not readable from the web server.

Bastien

Sent from my iPod

On Mar 7, 2009, at 5:04, Sashikanth Gurram <sashi34u@xxxxxx> wrote:

Hi,

Yes. But I assign the location of the image ( C:\Users\Sashikanth\Desktop\Bldgs_lots\Burruss.jpg) to the $location variable by using the mysqli_fetch_array($data) command. I send a query to the db and the result is obtained and the image location is stored into $location. So it is pretty straightforward. But I cannot understand why is it not displaying the picture after retrieving the image. Should I use any other additional commands to display the picture? Or do I need any changes in my PHP configuration file? I have checked the Config file and the ; sign infront of extension=php_gd2.dll has been removed.

Thanks,
Sashi



Hello,

Does something like this work on your php script?

$location="..\..\Bldgs_lots\Burruss.jpg"

OR

$location="..\Bldgs_lots\Burruss.jpg"




GR
Muhsin



Sashikanth Gurram wrote:

This is the location where I have saved  my images.
/C:\Users\Sashikanth\Desktop\Bldgs_lots\Burruss.jpg
/I have loaded the above location exactly into my database. But when I
call it using

/echo "<img src='$location' border='1' height='150' width='200'
alt='$build' >";/

It is simply giving me some blank empty space, with the name of the
picture in the blank space (Since I am using alt). So, as I see it,
the retrieval part is working fine, but the displaying of the image is
not functioning properly. I am using a WAMP server. Any kind of
suggestions are welcome.

Thanks,
Sashi

PS: For Reference, I am posting my entire code below again. The image
retrieval part is towards the end of the code.

/<html>
<body>
<form action="mysqli.php" method="post">
<br>
<div align="center">
Building Name:<select name="name">
<option value=""> Select a Building</option>
    <option value="Military Building">Military Building</option>
    <option value="Monteith Hall">Monteith Hall</option>
    <option value="New Residence Hall-Career Services Site">New
Residence Hall-Career Services Site</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>
</select>
</div>
                  <input type="submit" />
</form>
<img src="mysqli.php?">

<?php
// Connects to your Database
$host="******";
$user="*******";
$password="********";
$dbname="*********";
$cxn=mysqli_connect($host, $user, $password, $dbname) ;
if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
  {
      $error=mysqli_error($cxn);
      echo "$error";
      die();
  }
else
  {
      echo "Connection established successfully";
  }
//Define the variables for Day and Month
$Today=date("l");
$Month=date("F");
$build=$_POST["name"];
$low_speed=2.5;
$high_speed=4;
$hour=date("G");
$minute=date("i");
if ($minute>=00 && $minute<=14)
  {
      $minute=00;
  }
elseif ($minute>=15 && $minute<=29)
  {
      $minute=15;
  }
elseif ($minute>=30 && $minute<=44)
  {
      $minute=30;
  }
else
  {
      $minute=45;
  }
$times="10:$minute";
$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))
  {
      $error=mysqli_error($cxn);
      echo "$error";
      die();
  }
else
  {
      echo "<br>";
      echo "Query sent successfully";
  }
echo "<br>";
echo "<h1> PARKING LOT INFORMATION <h1>";
echo "<table border='1' cellspacing='5' cellpadding='2'>";
echo "<tr>\n
      <th>Building</th>\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
  </tr>\n";
while ($row=mysqli_fetch_array($data))
  {
      extract($row);
$building = $row[0];
    $parking_lot = $row[1];
    $Number_of_Empty_Spaces = $row[2];
    $Distance = $row[3];
    $time_l = $row[4];
    $time_h=$row[5];
    $location=$row[6];   echo "<tr>\n
            <td>$building</td>\n
<td>$parking_lot</td>\n <td>$Number_of_Empty_Spaces</td>\n
            <td>$Distance</td>\n
            <td>$time_h - $time_l mins</td>\n
<td>$location</td>\n
            </tr>\n";
  }
  echo "</table>\n";
echo "<img src='$location' border='1' height='150' width='200'
alt='$build' >";
?>
</body>
</html>/


mrfroasty wrote:

Hello,

It might be something with location where the script is located and the
image.I think is normally the case if they arent on the same
directory...
If not you might want to try saving your image locations with something
like ../../image_folder/image.jpg

I am not sure though as I have seen this issue on one application but
it runs on LAMP

P:S
../ One step back from the script location


GR
Muhsin


Sashikanth Gurram wrote:

Hi,
Thanks a lot for the suggestion. It is working fine but there is some
problem. When I introduced the piece of code you have suggested into
my code, I am getting a space for the picture but nothing is there in that space. It is just blank. I do not know the reason for this. I am just attaching a picture just in case it might give you a better idea. Further, this is the piece of code I have written to display the pic.

/echo "<img src='$location' border='1' height='150' width='200'
alt='$build' >";/

Any help would be greatly appreciated.
Thanks,
Sashi

mrfroasty wrote:

Hello,

Storing only location of the image in dB wouldnt be any different than
other string/data retrieved from the dB.That means if you have
something
like this in html documents whereby $image_location comes from the dB
It should work without ....header stuffs

Example
<img src="$image_location" border="1" height="150" width="200"
alt="Image" ISMAP>
P:S
Replace $image_location with image location from your dB.


GR
Muhsin



Sashikanth Gurram wrote:

Dear all,

I have been trying to retrieve the location of a image from database and display the image in the browser using PHP. I have written a sort of code for the purpose. All I am getting in my browser after using the code is a long set of ASCII characters with the following 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 *237
*
I am herewith attaching my code. If anyone can  point out the
error or
give some kind of advice that would be really great. The location of
the image is stored in a table by the name IMAGE under the column
name
Location and here in the code, the location is retrieved under the
varibale name $Location.

thanks,
Sashi

/<html>
<body>
<form action="mysqli.php" method="post">
<br>
<div align="center">
Building Name:<select name="name">
<option value=""> Select a Building</option>
<option value="Agnew Hall">Agnew Hall</option>
    <option value="Rector Field House">Rector Field House</option>
    <option value="Richard B. Talbot Educational Resources
Center">Richard B. Talbot Educational Resources Center</option>
    <option value="Robeson Hall">Robeson Hall</option>
    <option value="Sandy Hall">Sandy Hall</option>
    <option value="Saunders hall">Saunders hall</option>
    <option value="Seitz Hall">Seitz Hall</option>
    <option value="Shanks Hall">Shanks Hall</option>
    <option value="Shultz Hall">Shultz Hall</option>
    <option value="Skelton Conference Center">Skelton Conference
Center</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>
</select>
</div>
                  <input type="submit" />
</form>
<img src="mysqli.php?">

<?php
// Connects to your Database
$host="*******";
$user="*****";
$password="******";
$dbname="*******";
$cxn=mysqli_connect($host, $user, $password, $dbname) ;
if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
  {
      $error=mysqli_error($cxn);
      echo "$error";
      die();
  }
else
  {
      echo "Connection established successfully";
  }
//Define the variables for Day and Month
$Today=date("l");
$Month=date("F");
$build=$_POST["name"];
$low_speed=2.5;
$high_speed=4;
$hour=date("G");
$minute=date("i");
if ($minute>=00 && $minute<=14)
  {
      $minute=00;
  }
elseif ($minute>=15 && $minute<=29)
  {
      $minute=15;
  }
elseif ($minute>=30 && $minute<=44)
  {
      $minute=30;
  }
else
  {
      $minute=45;
  }
$times="$hour:$minute";
$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='$Today' AND Time='$times'";
$data = mysqli_query($cxn,$sql);
if (!$data=mysqli_query($cxn,$sql))
  {
      $error=mysqli_error($cxn);
      echo "$error";
      die();
  }
else
  {
      echo "<br>";
      echo "Query sent successfully";
  }
echo "<br>";
echo "<h1> PARKING LOT INFORMATION <h1>";
echo "<table border='1' cellspacing='5' cellpadding='2'>";
echo "<tr>\n
      <th>Building</th>\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
  </tr>\n";
while ($row=mysqli_fetch_array($data))
  {
      extract($row);
$building = $row[0];
    $parking_lot = $row[1];
    $Number_of_Empty_Spaces = $row[2];
    $Distance = $row[3];
    $time_l = $row[4];
    $time_h=$row[5];
    $location=$row[6];   echo "<tr>\n
            <td>$building</td>\n
<td>$parking_lot</td>\n <td>$Number_of_Empty_Spaces</td>\n
            <td>$Distance</td>\n
            <td>$time_h - $time_l mins</td>\n
<td>$location</td>\n
            </tr>\n";
  }
  echo "</table>\n";
$err=1;
if ($img = file_get_contents($location, FILE_BINARY))
{
if ($img = imagecreatefromstring($img)) $err = 0;
}
if ($err)
{
header('Content-Type: text/html');
echo '<html><body><p style="font-size:9px">Error getting
image...</p></body></html>';
}
else
{
header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);
}
?>
</body>
</html>/

Sashikanth Gurram wrote:

Hello guys,

Thanks to you all for your kind replies. I will try the steps and
get
back to you if I encounter more problems.

Thanks,
Sashi

Fortuno, Adam wrote:

Matya,

Ha, ha, ha! Thank you good friend. I did say I didn't try the code
:-)

AF> Please note, I haven't tried this. It just seems plausible.

I apologize if I confused anyone. I just meant to show how the
parameter could help retrieve a picture. I wasn't too concerned
with
the particulars. Hopefully the concept is sound. If not, please do
flame my note so no one attempts it.

Be Well,
A-

-----Original Message-----
From: Mattyasovszky Janos [mailto:mail@xxxxxxxx] Sent: Monday,
March
02, 2009 9:29 AM
To: php-db@xxxxxxxxxxxxx
Subject: Re:  Retrieving Image Location in MySQL

Fortuno, Adam írta:


       //Write a query to pull out the picture's path
       $sql = "SELECT path FROM Image WHERE ID = %s";
       mysql_real_escape_string($value);

Sorry, but this won't work, since you don't map the value of the
escaped $value to the %s, lets say with sprintf()...

Regards,
Matya





------------------------------------------------------------------------










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


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




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


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux