Retrieving Image Location in MySQL

Retrieving Image Location in MySQL

am 02.03.2009 04:26:47 von Sashikanth Gurram

Dear All,

I am trying to retrieve the location of a image (not the image, just the
location of the image) stored on MySQL database, using PHP to display it
in my browser. One of the users has been kind enough to provide me with
an example code as to how to do it. He asked me to use / src="picture.php?&qry=123"> /in the html code. I understood the part of
/picture.php? /which tells us that the php code used to retrieve the
image is located in the file picture.php (If what I have understood is
correct). But I did not quite understand the second part /&qry=123 /.
What does this mean? Of what use is this second part? Does the variable
&qry has something assigned to it in the picture.php code? I would
greatly appreciate it if any one of you can answer my questions.

Thanks,
Sashi

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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

RE: Retrieving Image Location in MySQL

am 02.03.2009 14:43:00 von Adam.Fortuno

Sashi,

This (likely) means you have a some generic page (i.e., picture.php)
that displays some picture. The picture it displays depends on the
parameter passed when the page is called (i.e., 123).



Sashi's Test Page



$value =3D $_GET ['qry'];
=09
//Get your parameter
if (!$value) die("Uh oh, trying to call the page without
a valid qry value.");
=09
//Write a query to pull out the picture's path
$sql =3D "SELECT path FROM Image WHERE ID =3D %s";
mysql_real_escape_string($value);
=09
//Execute the query
$output =3D mysql_query($sql);
=09
//Display the corresponding picture
while ($row =3D mysql_fetch_assoc($output)) {
printf("", $row['firstname']);
}
=09
//Clean up
mysql_free_result($output);

?>



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

Good luck.

A-

-----Original Message-----
From: Sashikanth Gurram [mailto:sashi34u@vt.edu]=20
Sent: Sunday, March 01, 2009 10:27 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Retrieving Image Location in MySQL

Dear All,

I am trying to retrieve the location of a image (not the image, just the

location of the image) stored on MySQL database, using PHP to display it

in my browser. One of the users has been kind enough to provide me with=20
an example code as to how to do it. He asked me to use / src=3D"picture.php?&qry=3D123"> /in the html code. I understood the part =
of=20
/picture.php? /which tells us that the php code used to retrieve the=20
image is located in the file picture.php (If what I have understood is=20
correct). But I did not quite understand the second part /&qry=3D123 /.=20
What does this mean? Of what use is this second part? Does the variable=20
&qry has something assigned to it in the picture.php code? I would=20
greatly appreciate it if any one of you can answer my questions.

Thanks,
Sashi

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


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


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

Re: Retrieving Image Location in MySQL

am 02.03.2009 15:29:14 von Mattyasovszky Janos

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

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

RE: Retrieving Image Location in MySQL

am 02.03.2009 22:27:45 von Adam.Fortuno

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@matya.hu]=20
Sent: Monday, March 02, 2009 9:29 AM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Retrieving Image Location in MySQL

Fortuno, Adam =EDrta:

> //Write a query to pull out the picture's path
> $sql =3D "SELECT path FROM Image WHERE ID =3D %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

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


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

Re: Retrieving Image Location in MySQL

am 02.03.2009 22:33:03 von Sashikanth Gurram

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@matya.hu]
> Sent: Monday, March 02, 2009 9:29 AM
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 06.03.2009 18:23:31 von Sashikanth Gurram

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

/





Building Name:





// 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 "
";
echo "Query sent successfully";
}
echo "
";
echo "

PARKING LOT INFORMATION

";
echo "";
echo "\n
\n
\n
\n
\n
\n
\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 "\n
\n
\n
\n
\n
\n
\n
\n";
}
echo "
Building Parking Lot Estimated Number of Empty Spaces Distance (Feet) Estimated walking time to the building
$building $parking_lot $Number_of_Empty_Spaces $Distance $time_h - $time_l mins $location
\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 '

Error getting
image...

';
}
else
{
header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);
}
?>

/

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@matya.hu] Sent: Monday, March
>> 02, 2009 9:29 AM
>> To: php-db@lists.php.net
>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 06.03.2009 19:06:21 von Joao Gomes Madeira

Hi Sashi:

You're incurring in this error because the headers for the page have
already been issued in the head section of your page.
When you issue the php header() function, it will generate an error.

Anyway, you are storing a path to a file in the database. My question
is: do you want to put your images on a subfolder of your site, where
they will become acessible through regular URLS, or you want to keep
them private and only accessible by scripting?

Cheers.
JP

-----Original Message-----
From: Sashikanth Gurram
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Retrieving Image Location in MySQL
Date: Fri, 06 Mar 2009 12:23:31 -0500

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

/





Building Name:





// 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 "
";
echo "Query sent successfully";
}
echo "
";
echo "

PARKING LOT INFORMATION

";
echo "";
echo "\n
\n
\n
\n
\n
\n
\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 "\n
\n
\n
\n
\n
\n
\n
\n";
}
echo "
Building Parking Lot Estimated Number of Empty Spaces Distance (Feet) Estimated walking time to the building
$building $parking_lot $Number_of_Empty_Spaces $Distance $time_h - $time_l mins $location
\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 '

Error getting
image...

';
}
else
{
header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);
}
?>

/

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@matya.hu] Sent: Monday, March
>> 02, 2009 9:29 AM
>> To: php-db@lists.php.net
>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 06.03.2009 19:37:01 von Phpster

--0016362836021e1e800464779298
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Fri, Mar 6, 2009 at 1:06 PM, Joao Gomes Madeira wrot=
e:

> Hi Sashi:
>
> You're incurring in this error because the headers for the page have
> already been issued in the head section of your page.
> When you issue the php header() function, it will generate an error.
>
> Anyway, you are storing a path to a file in the database. My question
> is: do you want to put your images on a subfolder of your site, where
> they will become acessible through regular URLS, or you want to keep
> them private and only accessible by scripting?
>
> Cheers.
> JP
>
> -----Original Message-----
> From: Sashikanth Gurram
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Retrieving Image Location in MySQL
> Date: Fri, 06 Mar 2009 12:23:31 -0500
>
> 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
>
> /
>
>


>

>

> Building Name:
>

>
>

>
>
> > // Connects to your Database
> $host=3D"*******";
> $user=3D"*****";
> $password=3D"******";
> $dbname=3D"*******";
> $cxn=3Dmysqli_connect($host, $user, $password, $dbname) ;
> if (!$cxn=3Dmysqli_connect($host, $user, $password, $dbname))
> {
> $error=3Dmysqli_error($cxn);
> echo "$error";
> die();
> }
> else
> {
> echo "Connection established successfully";
> }
> //Define the variables for Day and Month
> $Today=3Ddate("l");
> $Month=3Ddate("F");
> $build=3D$_POST["name"];
> $low_speed=3D2.5;
> $high_speed=3D4;
> $hour=3Ddate("G");
> $minute=3Ddate("i");
> if ($minute>=3D00 && $minute<=3D14)
> {
> $minute=3D00;
> }
> elseif ($minute>=3D15 && $minute<=3D29)
> {
> $minute=3D15;
> }
> elseif ($minute>=3D30 && $minute<=3D44)
> {
> $minute=3D30;
> }
> else
> {
> $minute=3D45;
> }
> $times=3D"$hour:$minute";
> $sql=3D"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=3Doccupancy2.building AND
> buildings.buildingcode=3Dbuildings_lots.building_code AND
> parkinglots.parking_lot_code=3Dbuildings_lots.parking_lot_co de AND
> parkinglots.parking_lot_code=3Doccupancy2.parking_lot AND
> Buildings.BuildingCode=3DImage.BuildingCode) AND buildingname=3D'$build' =
AND
> month=3D'$Month' AND day=3D'$Today' AND Time=3D'$times'";
> $data =3D mysqli_query($cxn,$sql);
> if (!$data=3Dmysqli_query($cxn,$sql))
> {
> $error=3Dmysqli_error($cxn);
> echo "$error";
> die();
> }
> else
> {
> echo "
";
> echo "Query sent successfully";
> }
> echo "
";
> echo "

PARKING LOT INFORMATION

";
> echo "";
> echo "\n
> \n
> \n
> \n
> \n
> \n
> \n";
> while ($row=3Dmysqli_fetch_array($data))
> {
> extract($row);
> $building =3D $row[0];
> $parking_lot =3D $row[1];
> $Number_of_Empty_Spaces =3D $row[2];
> $Distance =3D $row[3];
> $time_l =3D $row[4];
> $time_h=3D$row[5];
> $location=3D$row[6];
> echo "\n
> \n
> \n
> \n
> \n
> \n
> \n
> \n";
> }
> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\n";
> $err=3D1;
> if ($img =3D file_get_contents($location, FILE_BINARY))
> {
> if ($img =3D imagecreatefromstring($img)) $err =3D 0;
> }
> if ($err)
> {
> header('Content-Type: text/html');
> echo '

Error getting
> image...

';
> }
> else
> {
> header('Content-Type: image/jpeg');
> imagejpeg($img);
> imagedestroy($img);
> }
> ?>
>
> /
>
> 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@matya.hu] Sent: Monday, March
> >> 02, 2009 9:29 AM
> >> To: php-db@lists.php.net
> >> Subject: Re: [PHP-DB] Retrieving Image Location in MySQL
> >>
> >> Fortuno, Adam =EDrta:
> >>
> >>
> >>> //Write a query to pull out the picture's path
> >>> $sql =3D "SELECT path FROM Image WHERE ID =3D %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
>
>
What I normally do is to use php to create the main page and then reference
the image in the img tag like this



where the 1234 is the image I want to fetch. Then that page just handles th=
e
image is something like
// database connection
$conn =3D mysql_connect("localhost", "user", "password")
OR DIE (mysql_error());
@mysql_select_db ($db, $conn) OR DIE (mysql_error());
$sql =3D "SELECT * FROM image WHERE image_id=3D".$_GET["id"];
$result =3D mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
$row =3D @mysql_fetch_array ($result);
$image_type =3D $row["image_type"];
$image =3D $row["image"];
Header ("Content-type: $image_type");
print $image;
}
?>
--=20

Bastien

Cat, the other other white meat

--0016362836021e1e800464779298--

Re: Retrieving Image Location in MySQL

am 06.03.2009 21:35:59 von Sashikanth Gurram

Hi JP,

I am just storing the location of the image on the database. I want to
keep them private and retrieve them through scripting. The images are
stored in a folder on my PC. Just to give you an example, this is the
location of a particular image as stored in the database.

C:\Users\Sashikanth\Desktop\Bldgs_lots\Burruss.jpg

Thanks,
Sashi

Joao Gomes Madeira wrote:
> Hi Sashi:
>
> You're incurring in this error because the headers for the page have
> already been issued in the head section of your page.
> When you issue the php header() function, it will generate an error.
>
> Anyway, you are storing a path to a file in the database. My question
> is: do you want to put your images on a subfolder of your site, where
> they will become acessible through regular URLS, or you want to keep
> them private and only accessible by scripting?
>
> Cheers.
> JP
>
> -----Original Message-----
> From: Sashikanth Gurram
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Retrieving Image Location in MySQL
> Date: Fri, 06 Mar 2009 12:23:31 -0500
>
> 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
>
> /
>
>


>

>

> Building Name:
>

>
>

>
>
> > // 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 "
";
> echo "Query sent successfully";
> }
> echo "
";
> echo "

PARKING LOT INFORMATION

";
> echo "";
> echo "\n
> \n
> \n
> \n
> \n
> \n
> \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 "\n
> \n
> \n
> \n
> \n
> \n
> \n
> \n";
> }
> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
> image...

';
> }
> else
> {
> header('Content-Type: image/jpeg');
> imagejpeg($img);
> imagedestroy($img);
> }
> ?>
>
> /
>
> 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@matya.hu] Sent: Monday, March
>>> 02, 2009 9:29 AM
>>> To: php-db@lists.php.net
>>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 07.03.2009 07:37:31 von muhsin

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
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
>
> /
>
>


>

>

> Building Name:
>

>
>

>
>
> > // 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 "
";
> echo "Query sent successfully";
> }
> echo "
";
> echo "

PARKING LOT INFORMATION

";
> echo "";
> echo "\n
> \n
> \n
> \n
> \n
> \n
> \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 "\n
> \n
> \n
> \n
> \n
> \n
> \n
> \n";
> }
> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
> image...

';
> }
> else
> {
> header('Content-Type: image/jpeg');
> imagejpeg($img);
> imagedestroy($img);
> }
> ?>
>
> /
>
> 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@matya.hu] Sent: Monday, March
>>> 02, 2009 9:29 AM
>>> To: php-db@lists.php.net
>>> Subject: Re: [PHP-DB] 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
>>>
>>>
>>
>>
>
>


--
Extra details:
OSS:Gentoo Linux-2.6.25-r8
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,VB,VHDL,bash
Typo:40WPM
url:http://mambo-tech.net


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

Re: Retrieving Image Location in MySQL

am 07.03.2009 08:38:51 von Sashikanth Gurram

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. Further,
this is the piece of code I have written to display the pic.

echo " 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
> > 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
>>
>> /
>>
>>


>>

>>

>> Building Name:
>>

>>
>>

>>
>>
>> >> // 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 "
";
>> echo "Query sent successfully";
>> }
>> echo "
";
>> echo "

PARKING LOT INFORMATION

";
>> echo "";
>> echo "\n
>> \n
>> \n
>> \n
>> \n
>> \n
>> \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 "\n
>> \n
>> \n
>> \n
>> \n
>> \n
>> \n
>> \n";
>> }
>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
>> image...

';
>> }
>> else
>> {
>> header('Content-Type: image/jpeg');
>> imagejpeg($img);
>> imagedestroy($img);
>> }
>> ?>
>>
>> /
>>
>> 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@matya.hu] Sent: Monday, March
>>>> 02, 2009 9:29 AM
>>>> To: php-db@lists.php.net
>>>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 07.03.2009 10:22:46 von Sashikanth Gurram

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 " 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.

/





Building Name:





// 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 "
";
echo "Query sent successfully";
}
echo "
";
echo "

PARKING LOT INFORMATION

";
echo "";
echo "\n
\n
\n
\n
\n
\n
\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 "\n
\n
\n
\n
\n
\n
\n
\n";
}
echo "
Building Parking Lot Estimated Number of Empty Spaces Distance (Feet) Estimated walking time to the building
$building $parking_lot $Number_of_Empty_Spaces $Distance $time_h - $time_l mins $location
\n";
echo " alt='$build' >";
?>

/


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 " >> 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
>>> >>> 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
>>>>
>>>> /
>>>>
>>>>

>>>>

>>>>

>>>> Building Name:
>>>>

>>>>
>>>>

>>>>
>>>>
>>>> >>>> // 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 "
";
>>>> echo "Query sent successfully";
>>>> }
>>>> echo "
";
>>>> echo "

PARKING LOT INFORMATION

";
>>>> echo "";
>>>> echo "\n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \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 "\n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n";
>>>> }
>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
>>>> image...

';
>>>> }
>>>> else
>>>> {
>>>> header('Content-Type: image/jpeg');
>>>> imagejpeg($img);
>>>> imagedestroy($img);
>>>> }
>>>> ?>
>>>>
>>>> /
>>>>
>>>> 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@matya.hu] Sent: Monday, March
>>>>>> 02, 2009 9:29 AM
>>>>>> To: php-db@lists.php.net
>>>>>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 07.03.2009 10:52:46 von muhsin

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 " > 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.
>
> /
>
>


>

>

> Building Name:
>

>
>

>
>
> > // 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 "
";
> echo "Query sent successfully";
> }
> echo "
";
> echo "

PARKING LOT INFORMATION

";
> echo "";
> echo "\n
> \n
> \n
> \n
> \n
> \n
> \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 "\n
> \n
> \n
> \n
> \n
> \n
> \n
> \n";
> }
> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\n";
> echo " > alt='$build' >";
> ?>
>
> /
>
>
> 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 " >>> 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
>>>> >>>> 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
>>>>>
>>>>> /
>>>>>
>>>>>

>>>>>

>>>>>

>>>>> Building Name:
>>>>>

>>>>>
>>>>>

>>>>>
>>>>>
>>>>> >>>>> // 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 "
";
>>>>> echo "Query sent successfully";
>>>>> }
>>>>> echo "
";
>>>>> echo "

PARKING LOT INFORMATION

";
>>>>> echo "";
>>>>> echo "\n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \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 "\n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \n
>>>>> \n";
>>>>> }
>>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
>>>>> image...

';
>>>>> }
>>>>> else
>>>>> {
>>>>> header('Content-Type: image/jpeg');
>>>>> imagejpeg($img);
>>>>> imagedestroy($img);
>>>>> }
>>>>> ?>
>>>>>
>>>>> /
>>>>>
>>>>> 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@matya.hu] Sent: Monday,
>>>>>>> March
>>>>>>> 02, 2009 9:29 AM
>>>>>>> To: php-db@lists.php.net
>>>>>>> Subject: Re: [PHP-DB] 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
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>> ------------------------------------------------------------ ------------
>>>
>>>
>>>
>>
>>
>>
>
>


--
Extra details:
OSS:Gentoo Linux-2.6.25-r8
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,VB,VHDL,bash
Typo:40WPM
url:http://mambo-tech.net


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

Re: Retrieving Image Location in MySQL

am 07.03.2009 11:04:22 von Sashikanth Gurram

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 " >> 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.
>>
>> /
>>
>>


>>

>>

>> Building Name:
>>

>>
>>

>>
>>
>> >> // 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 "
";
>> echo "Query sent successfully";
>> }
>> echo "
";
>> echo "

PARKING LOT INFORMATION

";
>> echo "";
>> echo "\n
>> \n
>> \n
>> \n
>> \n
>> \n
>> \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 "\n
>> \n
>> \n
>> \n
>> \n
>> \n
>> \n
>> \n";
>> }
>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\n";
>> echo " >> alt='$build' >";
>> ?>
>>
>> /
>>
>>
>> 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 " >>>> 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
>>>>> >>>>> 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
>>>>>>
>>>>>> /
>>>>>>
>>>>>>

>>>>>>

>>>>>>

>>>>>> Building Name:
>>>>>>

>>>>>>
>>>>>>

>>>>>>
>>>>>>
>>>>>> >>>>>> // 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 "
";
>>>>>> echo "Query sent successfully";
>>>>>> }
>>>>>> echo "
";
>>>>>> echo "

PARKING LOT INFORMATION

";
>>>>>> echo "";
>>>>>> echo "\n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \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 "\n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n";
>>>>>> }
>>>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
>>>>>> image...

';
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> header('Content-Type: image/jpeg');
>>>>>> imagejpeg($img);
>>>>>> imagedestroy($img);
>>>>>> }
>>>>>> ?>
>>>>>>
>>>>>> /
>>>>>>
>>>>>> 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@matya.hu] Sent: Monday,
>>>>>>>> March
>>>>>>>> 02, 2009 9:29 AM
>>>>>>>> To: php-db@lists.php.net
>>>>>>>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 07.03.2009 11:08:08 von Joao Gomes Madeira

Hello again Sashi

The answer provided by Mushin won't work because images are not
acessible from the outside. You can't have



because that's not a valid URL...

You can have something like



which when interpreted by the browser will become something like

http://yoursite/Bldgs_lots/Burruss.jpg

Now, for this to happen you need to have Bldgs_lots as a subfolder or
alias for your site.

Otherwise, there is the way I mentioned in the first place, involving a
php script just to get the image, which has to be called from within
your script, passing it the info from the database

echo ' alt="' . $build . '">';

Now, I don't recommend passing local paths like this to scripts ...

Hope this helps
C ya
JP


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

Re: Retrieving Image Location in MySQL

am 07.03.2009 11:36:43 von Sashikanth Gurram

Hi JP,
Thanks for chipping in again. I have been using the following code
(after retrieving the local location of my image to the variable
$location. I am not really looking to host the pictures onto a site as
of now), which u have earlier provided me with
/
$err=1;
if ($img = file_get_contents("$location", FILE_BINARY))
{
if ($img = imagecreatefromstring($img)) $err = 0;
}
if ($err)
{
header('Content-Type: text/html');
echo '

Error getting
image...

';
}
else
{
header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);
}
/
I am just using this and nothing more, and I have been getting a warning
of sort "CANNOT MODIFY HEADER INFORMATION-HEADERS ALREADY SENT ......ON
LINE 234". I have looked about this warning online and i found that this
occurs when the output is sent to the browser before the headers. From
the look of the above code, I dont think I am sending the info to the
browser before the headers. Also, when I use the above code, I see a lot
of ASCII characters in my browser. May be, the image is encrypted into
some form and the encrypted form is being displayed instead of the
picture. Further, you have always mentioned about using

img src="picture.php?&img=1234. I did not clearly understand where to put it in the code. Is it a part of HTML code or is it a part of PHP code?


Thanks,
Sashi



Joao Gomes Madeira wrote:
> Hello again Sashi
>
> The answer provided by Mushin won't work because images are not
> acessible from the outside. You can't have
>
>
>
> because that's not a valid URL...
>
> You can have something like
>
>
>
> which when interpreted by the browser will become something like
>
> http://yoursite/Bldgs_lots/Burruss.jpg
>
> Now, for this to happen you need to have Bldgs_lots as a subfolder or
> alias for your site.
>
> Otherwise, there is the way I mentioned in the first place, involving a
> php script just to get the image, which has to be called from within
> your script, passing it the info from the database
>
> echo ' > alt="' . $build . '">';
>
> Now, I don't recommend passing local paths like this to scripts ...
>
> Hope this helps
> C ya
> JP
>
>
>


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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

Re: Retrieving Image Location in MySQL

am 07.03.2009 16:31:33 von Phpster

Bet the image is not readable from the web server.

Bastien

Sent from my iPod

On Mar 7, 2009, at 5:04, Sashikanth Gurram wrote:

> Hi,
>
> Yes. But I assign the location of the image ( C:\Users\Sashikanth=20
> \Desktop\Bldgs_lots\Burruss.jpg) to the $location variable by using =20=

> the mysqli_fetch_array($data) command. I send a query to the db and =20=

> the result is obtained and the image location is stored into =20
> $location. So it is pretty straightforward. But I cannot understand =20=

> why is it not displaying the picture after retrieving the image. =20
> Should I use any other additional commands to display the picture? =20
> Or do I need any changes in my PHP configuration file? I have =20
> checked the Config file and the ; sign infront of =20
> extension=3Dphp_gd2.dll has been removed.
>
> Thanks,
> Sashi
>
>
>
>> Hello,
>>
>> Does something like this work on your php script?
>>
>> $location=3D"..\..\Bldgs_lots\Burruss.jpg"
>>
>> OR
>>
>> $location=3D"..\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 =20
>>> when I
>>> call it using
>>>
>>> /echo " width=3D'200'
>>> alt=3D'$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 =20
>>> 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 =20
>>> image
>>> retrieval part is towards the end of the code.
>>>
>>> /
>>>
>>>


>>>

>>>

>>> Building Name:
>>>

>>>
>>>

>>>
>>>
>>> >>> // Connects to your Database
>>> $host=3D"******";
>>> $user=3D"*******";
>>> $password=3D"********";
>>> $dbname=3D"*********";
>>> $cxn=3Dmysqli_connect($host, $user, $password, $dbname) ;
>>> if (!$cxn=3Dmysqli_connect($host, $user, $password, $dbname))
>>> {
>>> $error=3Dmysqli_error($cxn);
>>> echo "$error";
>>> die();
>>> }
>>> else
>>> {
>>> echo "Connection established successfully";
>>> }
>>> //Define the variables for Day and Month
>>> $Today=3Ddate("l");
>>> $Month=3Ddate("F");
>>> $build=3D$_POST["name"];
>>> $low_speed=3D2.5;
>>> $high_speed=3D4;
>>> $hour=3Ddate("G");
>>> $minute=3Ddate("i");
>>> if ($minute>=3D00 && $minute<=3D14)
>>> {
>>> $minute=3D00;
>>> }
>>> elseif ($minute>=3D15 && $minute<=3D29)
>>> {
>>> $minute=3D15;
>>> }
>>> elseif ($minute>=3D30 && $minute<=3D44)
>>> {
>>> $minute=3D30;
>>> }
>>> else
>>> {
>>> $minute=3D45;
>>> }
>>> $times=3D"10:$minute";
>>> $sql=3D"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=3Doccupancy2.building AND =20
>>> buildings.buildingcode=3Dbuildings_lots.building_code AND
>>> parkinglots.parking_lot_code=3Dbuildings_lots.parking_lot_co de AND
>>> parkinglots.parking_lot_code=3Doccupancy2.parking_lot AND
>>> Buildings.BuildingCode=3DImage.BuildingCode) AND =
buildingname=3D'$build'
>>> AND month=3D'$Month' AND day=3D'Monday' AND Time=3D'$times'";
>>> $data =3D mysqli_query($cxn,$sql);
>>> if (!$data=3Dmysqli_query($cxn,$sql))
>>> {
>>> $error=3Dmysqli_error($cxn);
>>> echo "$error";
>>> die();
>>> }
>>> else
>>> {
>>> echo "
";
>>> echo "Query sent successfully";
>>> }
>>> echo "
";
>>> echo "

PARKING LOT INFORMATION

";
>>> echo "";
>>> echo "\n
>>> \n
>>> \n
>>> \n
>>> \n
>>> \n
>>> \n";
>>> while ($row=3Dmysqli_fetch_array($data))
>>> {
>>> extract($row);
>>> $building =3D $row[0];
>>> $parking_lot =3D $row[1];
>>> $Number_of_Empty_Spaces =3D $row[2];
>>> $Distance =3D $row[3];
>>> $time_l =3D $row[4];
>>> $time_h=3D$row[5];
>>> $location=3D$row[6]; echo "\n
>>> \n
>>> \n \n
>>> \n
>>> \n
>>> \n
>>> \n";
>>> }
>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot=20
>>> $Number_of_Empty_Spaces
$Distance$time_h - $time_l mins$location
\n";
>>> echo "
>>> alt=3D'$build' >";
>>> ?>
>>>
>>> /
>>>
>>>
>>> mrfroasty wrote:
>>>
>>>> Hello,
>>>>
>>>> It might be something with location where the script is located =20=

>>>> 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 =20
>>>> something
>>>> like ../../image_folder/image.jpg
>>>>
>>>> I am not sure though as I have seen this issue on one =20
>>>> 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 =20=

>>>>> some
>>>>> problem. When I introduced the piece of code you have suggested =20=

>>>>> into
>>>>> my code, I am getting a space for the picture but nothing is =20
>>>>> there in
>>>>> that space. It is just blank. I do not know the reason for this. =20=

>>>>> I am
>>>>> just attaching a picture just in case it might give you a better =20=

>>>>> idea.
>>>>> Further, this is the piece of code I have written to display the =20=

>>>>> pic.
>>>>>
>>>>> /echo " width=3D'200'
>>>>> alt=3D'$build' >";/
>>>>>
>>>>> Any help would be greatly appreciated.
>>>>> Thanks,
>>>>> Sashi
>>>>>
>>>>> mrfroasty wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> Storing only location of the image in dB wouldnt be any =20
>>>>>> 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 =20=

>>>>>> the dB
>>>>>> It should work without ....header stuffs
>>>>>>
>>>>>> Example
>>>>>> width=3D"200"
>>>>>> alt=3D"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 =20
>>>>>>> database
>>>>>>> and display the image in the browser using PHP. I have written =20=

>>>>>>> a sort
>>>>>>> of code for the purpose. All I am getting in my browser after =20=

>>>>>>> using
>>>>>>> the code is a long set of ASCII characters with the following =20=

>>>>>>> warning
>>>>>>> *Warning*: Cannot modify header information - headers already =20=

>>>>>>> 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 =20
>>>>>>> location of
>>>>>>> the image is stored in a table by the name IMAGE under the =20
>>>>>>> column
>>>>>>> name
>>>>>>> Location and here in the code, the location is retrieved under =20=

>>>>>>> the
>>>>>>> varibale name $Location.
>>>>>>>
>>>>>>> thanks,
>>>>>>> Sashi
>>>>>>>
>>>>>>> /
>>>>>>>
>>>>>>>

>>>>>>>

>>>>>>>

>>>>>>> Building Name:
>>>>>>>

>>>>>>>
>>>>>>>

>>>>>>>
>>>>>>>
>>>>>>> >>>>>>> // Connects to your Database
>>>>>>> $host=3D"*******";
>>>>>>> $user=3D"*****";
>>>>>>> $password=3D"******";
>>>>>>> $dbname=3D"*******";
>>>>>>> $cxn=3Dmysqli_connect($host, $user, $password, $dbname) ;
>>>>>>> if (!$cxn=3Dmysqli_connect($host, $user, $password, $dbname))
>>>>>>> {
>>>>>>> $error=3Dmysqli_error($cxn);
>>>>>>> echo "$error";
>>>>>>> die();
>>>>>>> }
>>>>>>> else
>>>>>>> {
>>>>>>> echo "Connection established successfully";
>>>>>>> }
>>>>>>> //Define the variables for Day and Month
>>>>>>> $Today=3Ddate("l");
>>>>>>> $Month=3Ddate("F");
>>>>>>> $build=3D$_POST["name"];
>>>>>>> $low_speed=3D2.5;
>>>>>>> $high_speed=3D4;
>>>>>>> $hour=3Ddate("G");
>>>>>>> $minute=3Ddate("i");
>>>>>>> if ($minute>=3D00 && $minute<=3D14)
>>>>>>> {
>>>>>>> $minute=3D00;
>>>>>>> }
>>>>>>> elseif ($minute>=3D15 && $minute<=3D29)
>>>>>>> {
>>>>>>> $minute=3D15;
>>>>>>> }
>>>>>>> elseif ($minute>=3D30 && $minute<=3D44)
>>>>>>> {
>>>>>>> $minute=3D30;
>>>>>>> }
>>>>>>> else
>>>>>>> {
>>>>>>> $minute=3D45;
>>>>>>> }
>>>>>>> $times=3D"$hour:$minute";
>>>>>>> $sql=3D"SELECT buildingname, parking_lot_name, empty_spaces, =20
>>>>>>> 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=3Doccupancy2.building AND
>>>>>>> buildings.buildingcode=3Dbuildings_lots.building_code AND
>>>>>>> parkinglots.parking_lot_code=3Dbuildings_lots.parking_lot_co de =
AND
>>>>>>> parkinglots.parking_lot_code=3Doccupancy2.parking_lot AND
>>>>>>> Buildings.BuildingCode=3DImage.BuildingCode) AND =20
>>>>>>> buildingname=3D'$build'
>>>>>>> AND month=3D'$Month' AND day=3D'$Today' AND Time=3D'$times'";
>>>>>>> $data =3D mysqli_query($cxn,$sql);
>>>>>>> if (!$data=3Dmysqli_query($cxn,$sql))
>>>>>>> {
>>>>>>> $error=3Dmysqli_error($cxn);
>>>>>>> echo "$error";
>>>>>>> die();
>>>>>>> }
>>>>>>> else
>>>>>>> {
>>>>>>> echo "
";
>>>>>>> echo "Query sent successfully";
>>>>>>> }
>>>>>>> echo "
";
>>>>>>> echo "

PARKING LOT INFORMATION

";
>>>>>>> echo "";
>>>>>>> echo "\n
>>>>>>> \n
>>>>>>> \n
>>>>>>> \n
>>>>>>> \n
>>>>>>> \n
>>>>>>> \n";
>>>>>>> while ($row=3Dmysqli_fetch_array($data))
>>>>>>> {
>>>>>>> extract($row);
>>>>>>> $building =3D $row[0];
>>>>>>> $parking_lot =3D $row[1];
>>>>>>> $Number_of_Empty_Spaces =3D $row[2];
>>>>>>> $Distance =3D $row[3];
>>>>>>> $time_l =3D $row[4];
>>>>>>> $time_h=3D$row[5];
>>>>>>> $location=3D$row[6]; echo "\n
>>>>>>> \n
>>>>>>> \n \n
>>>>>>> \n
>>>>>>> \n
>>>>>>> \n
>>>>>>> \n";
>>>>>>> }
>>>>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot=20
>>>>>>> $Number_of_Empty_Spaces
$Distance$time_h - $time_l mins$location
\n";
>>>>>>> $err=3D1;
>>>>>>> if ($img =3D file_get_contents($location, FILE_BINARY))
>>>>>>> {
>>>>>>> if ($img =3D imagecreatefromstring($img)) $err =3D 0;
>>>>>>> }
>>>>>>> if ($err)
>>>>>>> {
>>>>>>> header('Content-Type: text/html');
>>>>>>> echo '

Error getting
>>>>>>> image...

';
>>>>>>> }
>>>>>>> else
>>>>>>> {
>>>>>>> header('Content-Type: image/jpeg');
>>>>>>> imagejpeg($img);
>>>>>>> imagedestroy($img);
>>>>>>> }
>>>>>>> ?>
>>>>>>>
>>>>>>> /
>>>>>>>
>>>>>>> Sashikanth Gurram wrote:
>>>>>>>
>>>>>>>> Hello guys,
>>>>>>>>
>>>>>>>> Thanks to you all for your kind replies. I will try the steps =20=

>>>>>>>> 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 =20
>>>>>>>>> the code
>>>>>>>>> :-)
>>>>>>>>>
>>>>>>>>> AF> Please note, I haven't tried this. It just seems =20
>>>>>>>>> plausible.
>>>>>>>>>
>>>>>>>>> I apologize if I confused anyone. I just meant to show how the
>>>>>>>>> parameter could help retrieve a picture. I wasn't too =20
>>>>>>>>> concerned
>>>>>>>>> with
>>>>>>>>> the particulars. Hopefully the concept is sound. If not, =20
>>>>>>>>> please do
>>>>>>>>> flame my note so no one attempts it.
>>>>>>>>>
>>>>>>>>> Be Well,
>>>>>>>>> A-
>>>>>>>>>
>>>>>>>>> -----Original Message-----
>>>>>>>>> From: Mattyasovszky Janos [mailto:mail@matya.hu] Sent: Monday,
>>>>>>>>> March
>>>>>>>>> 02, 2009 9:29 AM
>>>>>>>>> To: php-db@lists.php.net
>>>>>>>>> Subject: Re: [PHP-DB] Retrieving Image Location in MySQL
>>>>>>>>>
>>>>>>>>> Fortuno, Adam írta:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> //Write a query to pull out the picture's path
>>>>>>>>>> $sql =3D "SELECT path FROM Image WHERE ID =3D %s";
>>>>>>>>>> mysql_real_escape_string($value);
>>>>>>>>>>
>>>>>>>>> Sorry, but this won't work, since you don't map the value of =20=

>>>>>>>>> the
>>>>>>>>> escaped $value to the %s, lets say with sprintf()...
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> Matya
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>> ---=20
>>>>> ---=20
>>>>> ------------------------------------------------------------ ------
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>>
>>
>
>
> --=20
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Sashikanth Gurram
> Graduate Research Assistant
> Department of Civil and Environmental Engineering
> Virginia Tech
> Blacksburg, VA 24060, USA
>
>
> --=20
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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

Re: Retrieving Image Location in MySQL

am 08.03.2009 01:34:09 von Sashikanth Gurram

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 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 " >>>> 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.
>>>>
>>>> /
>>>>
>>>>


>>>>

>>>>

>>>> Building Name:
>>>>

>>>>
>>>>

>>>>
>>>>
>>>> >>>> // 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 "
";
>>>> echo "Query sent successfully";
>>>> }
>>>> echo "
";
>>>> echo "

PARKING LOT INFORMATION

";
>>>> echo "";
>>>> echo "\n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \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 "\n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n
>>>> \n";
>>>> }
>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\n";
>>>> echo " >>>> alt='$build' >";
>>>> ?>
>>>>
>>>> /
>>>>
>>>>
>>>> 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 " >>>>>> 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
>>>>>>> >>>>>>> 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
>>>>>>>>
>>>>>>>> /
>>>>>>>>
>>>>>>>>

>>>>>>>>

>>>>>>>>

>>>>>>>> Building Name:
>>>>>>>>

>>>>>>>>
>>>>>>>>

>>>>>>>>
>>>>>>>>
>>>>>>>> >>>>>>>> // 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 "
";
>>>>>>>> echo "Query sent successfully";
>>>>>>>> }
>>>>>>>> echo "
";
>>>>>>>> echo "

PARKING LOT INFORMATION

";
>>>>>>>> echo "";
>>>>>>>> echo "\n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \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 "\n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n
>>>>>>>> \n";
>>>>>>>> }
>>>>>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty_Spaces$Distance$time_h - $time_l mins$location
\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 '

Error getting
>>>>>>>> image...

';
>>>>>>>> }
>>>>>>>> else
>>>>>>>> {
>>>>>>>> header('Content-Type: image/jpeg');
>>>>>>>> imagejpeg($img);
>>>>>>>> imagedestroy($img);
>>>>>>>> }
>>>>>>>> ?>
>>>>>>>>
>>>>>>>> /
>>>>>>>>
>>>>>>>> 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@matya.hu] Sent: Monday,
>>>>>>>>>> March
>>>>>>>>>> 02, 2009 9:29 AM
>>>>>>>>>> To: php-db@lists.php.net
>>>>>>>>>> Subject: Re: [PHP-DB] 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

Re: Retrieving Image Location in MySQL

am 08.03.2009 02:13:30 von Kesavan Rengarajan

drop the images into a folder within your WAMP servers htdocs
directory and then update your database tables with the new location..
for security reasons you will not be able access files outside your
web directory through PHP
>
> On Sun, Mar 8, 2009 at 11:34 AM, Sashikanth Gurram wrot=
e:
>>
>> Hi,
>> I have tried it in 3 browsers (Chrome, firefox and internet explorer) an=
d 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 wrote:
>>>
>>>> Hi,
>>>>
>>>> Yes. But I assign the location of the image ( C:\Users\Sashikanth\Desk=
top\Bldgs_lots\Burruss.jpg) to the $location variable by using the mysqli_f=
etch_array($data) command. I send a query to the db and the result is obtai=
ned and the image location is stored into $location. So it is pretty straig=
htforward. But I cannot understand why is it not displaying the picture aft=
er retrieving the image. Should I use any other additional commands to disp=
lay 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=3Dphp_gd2.=
dll has been removed.
>>>>
>>>> Thanks,
>>>> Sashi
>>>>
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> Does something like this work on your php script?
>>>>>
>>>>> $location=3D"..\..\Bldgs_lots\Burruss.jpg"
>>>>>
>>>>> OR
>>>>>
>>>>> $location=3D"..\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 " 00'
>>>>>> alt=3D'$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 imag=
e
>>>>>> retrieval part is towards the end of the code.
>>>>>>
>>>>>> /
>>>>>>
>>>>>>


>>>>>>

>>>>>>

>>>>>> Building Name:
>>>>>>

>>>>>>
>>>>>>

>>>>>>
>>>>>>
>>>>>> >>>>>> // Connects to your Database
>>>>>> $host=3D"******";
>>>>>> $user=3D"*******";
>>>>>> $password=3D"********";
>>>>>> $dbname=3D"*********";
>>>>>> $cxn=3Dmysqli_connect($host, $user, $password, $dbname) ;
>>>>>> if (!$cxn=3Dmysqli_connect($host, $user, $password, $dbname))
>>>>>> {
>>>>>> $error=3Dmysqli_error($cxn);
>>>>>> echo "$error";
>>>>>> die();
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> echo "Connection established successfully";
>>>>>> }
>>>>>> //Define the variables for Day and Month
>>>>>> $Today=3Ddate("l");
>>>>>> $Month=3Ddate("F");
>>>>>> $build=3D$_POST["name"];
>>>>>> $low_speed=3D2.5;
>>>>>> $high_speed=3D4;
>>>>>> $hour=3Ddate("G");
>>>>>> $minute=3Ddate("i");
>>>>>> if ($minute>=3D00 && $minute<=3D14)
>>>>>> {
>>>>>> $minute=3D00;
>>>>>> }
>>>>>> elseif ($minute>=3D15 && $minute<=3D29)
>>>>>> {
>>>>>> $minute=3D15;
>>>>>> }
>>>>>> elseif ($minute>=3D30 && $minute<=3D44)
>>>>>> {
>>>>>> $minute=3D30;
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> $minute=3D45;
>>>>>> }
>>>>>> $times=3D"10:$minute";
>>>>>> $sql=3D"SELECT buildingname, parking_lot_name, empty_spaces, distanc=
e,
>>>>>> 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=3Doccupancy2.building AND buildings.building=
code=3Dbuildings_lots.building_code AND
>>>>>> parkinglots.parking_lot_code=3Dbuildings_lots.parking_lot_co de AND
>>>>>> parkinglots.parking_lot_code=3Doccupancy2.parking_lot AND
>>>>>> Buildings.BuildingCode=3DImage.BuildingCode) AND buildingname=3D'$bu=
ild'
>>>>>> AND month=3D'$Month' AND day=3D'Monday' AND Time=3D'$times'";
>>>>>> $data =3D mysqli_query($cxn,$sql);
>>>>>> if (!$data=3Dmysqli_query($cxn,$sql))
>>>>>> {
>>>>>> $error=3Dmysqli_error($cxn);
>>>>>> echo "$error";
>>>>>> die();
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> echo "
";
>>>>>> echo "Query sent successfully";
>>>>>> }
>>>>>> echo "
";
>>>>>> echo "

PARKING LOT INFORMATION

";
>>>>>> echo "";
>>>>>> echo "\n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n";
>>>>>> while ($row=3Dmysqli_fetch_array($data))
>>>>>> {
>>>>>> extract($row);
>>>>>> $building =3D $row[0];
>>>>>> $parking_lot =3D $row[1];
>>>>>> $Number_of_Empty_Spaces =3D $row[2];
>>>>>> $Distance =3D $row[3];
>>>>>> $time_l =3D $row[4];
>>>>>> $time_h=3D$row[5];
>>>>>> $location=3D$row[6]; echo "\n
>>>>>> \n
>>>>>> \n \n
>>>>>> \n
>>>>>> \n
>>>>>> \n
>>>>>> \n";
>>>>>> }
>>>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Empty=
_Spaces
$Distance$time_h - $time_l mins$location
\n";
>>>>>> echo " 0'
>>>>>> alt=3D'$build' >";
>>>>>> ?>
>>>>>>
>>>>>> /
>>>>>>
>>>>>>
>>>>>> mrfroasty wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> It might be something with location where the script is located an=
d 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 somet=
hing
>>>>>>> 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 s=
ome
>>>>>>>> problem. When I introduced the piece of code you have suggested in=
to
>>>>>>>> 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 i=
dea.
>>>>>>>> Further, this is the piece of code I have written to display the p=
ic.
>>>>>>>>
>>>>>>>> /echo " '200'
>>>>>>>> alt=3D'$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 th=
e dB
>>>>>>>>> It should work without ....header stuffs
>>>>>>>>>
>>>>>>>>> Example
>>>>>>>>> "200"
>>>>>>>>> alt=3D"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 data=
base
>>>>>>>>>> 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 us=
ing
>>>>>>>>>> the code is a long set of ASCII characters with the following wa=
rning
>>>>>>>>>> *Warning*: Cannot modify header information - headers already se=
nt 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 locatio=
n of
>>>>>>>>>> the image is stored in a table by the name IMAGE under the colum=
n
>>>>>>>>>> name
>>>>>>>>>> Location and here in the code, the location is retrieved under t=
he
>>>>>>>>>> varibale name $Location.
>>>>>>>>>>
>>>>>>>>>> thanks,
>>>>>>>>>> Sashi
>>>>>>>>>>
>>>>>>>>>> /
>>>>>>>>>>
>>>>>>>>>>

>>>>>>>>>>

>>>>>>>>>>

>>>>>>>>>> Building Name:
>>>>>>>>>>

>>>>>>>>>>
>>>>>>>>>>

>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> >>>>>>>>>> // Connects to your Database
>>>>>>>>>> $host=3D"*******";
>>>>>>>>>> $user=3D"*****";
>>>>>>>>>> $password=3D"******";
>>>>>>>>>> $dbname=3D"*******";
>>>>>>>>>> $cxn=3Dmysqli_connect($host, $user, $password, $dbname) ;
>>>>>>>>>> if (!$cxn=3Dmysqli_connect($host, $user, $password, $dbname))
>>>>>>>>>> {
>>>>>>>>>> $error=3Dmysqli_error($cxn);
>>>>>>>>>> echo "$error";
>>>>>>>>>> die();
>>>>>>>>>> }
>>>>>>>>>> else
>>>>>>>>>> {
>>>>>>>>>> echo "Connection established successfully";
>>>>>>>>>> }
>>>>>>>>>> //Define the variables for Day and Month
>>>>>>>>>> $Today=3Ddate("l");
>>>>>>>>>> $Month=3Ddate("F");
>>>>>>>>>> $build=3D$_POST["name"];
>>>>>>>>>> $low_speed=3D2.5;
>>>>>>>>>> $high_speed=3D4;
>>>>>>>>>> $hour=3Ddate("G");
>>>>>>>>>> $minute=3Ddate("i");
>>>>>>>>>> if ($minute>=3D00 && $minute<=3D14)
>>>>>>>>>> {
>>>>>>>>>> $minute=3D00;
>>>>>>>>>> }
>>>>>>>>>> elseif ($minute>=3D15 && $minute<=3D29)
>>>>>>>>>> {
>>>>>>>>>> $minute=3D15;
>>>>>>>>>> }
>>>>>>>>>> elseif ($minute>=3D30 && $minute<=3D44)
>>>>>>>>>> {
>>>>>>>>>> $minute=3D30;
>>>>>>>>>> }
>>>>>>>>>> else
>>>>>>>>>> {
>>>>>>>>>> $minute=3D45;
>>>>>>>>>> }
>>>>>>>>>> $times=3D"$hour:$minute";
>>>>>>>>>> $sql=3D"SELECT buildingname, parking_lot_name, empty_spaces, dis=
tance,
>>>>>>>>>> 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=3Doccupancy2.building AND
>>>>>>>>>> buildings.buildingcode=3Dbuildings_lots.building_code AND
>>>>>>>>>> parkinglots.parking_lot_code=3Dbuildings_lots.parking_lot_co de A=
ND
>>>>>>>>>> parkinglots.parking_lot_code=3Doccupancy2.parking_lot AND
>>>>>>>>>> Buildings.BuildingCode=3DImage.BuildingCode) AND buildingname=3D=
'$build'
>>>>>>>>>> AND month=3D'$Month' AND day=3D'$Today' AND Time=3D'$times'";
>>>>>>>>>> $data =3D mysqli_query($cxn,$sql);
>>>>>>>>>> if (!$data=3Dmysqli_query($cxn,$sql))
>>>>>>>>>> {
>>>>>>>>>> $error=3Dmysqli_error($cxn);
>>>>>>>>>> echo "$error";
>>>>>>>>>> die();
>>>>>>>>>> }
>>>>>>>>>> else
>>>>>>>>>> {
>>>>>>>>>> echo "
";
>>>>>>>>>> echo "Query sent successfully";
>>>>>>>>>> }
>>>>>>>>>> echo "
";
>>>>>>>>>> echo "

PARKING LOT INFORMATION

";
>>>>>>>>>> echo "";
>>>>>>>>>> echo "\n
>>>>>>>>>> \n
>>>>>>>>>> \n
>>>>>>>>>> \n
>>>>>>>>>> \n
>>>>>>>>>> \n
>>>>>>>>>> \n";
>>>>>>>>>> while ($row=3Dmysqli_fetch_array($data))
>>>>>>>>>> {
>>>>>>>>>> extract($row);
>>>>>>>>>> $building =3D $row[0];
>>>>>>>>>> $parking_lot =3D $row[1];
>>>>>>>>>> $Number_of_Empty_Spaces =3D $row[2];
>>>>>>>>>> $Distance =3D $row[3];
>>>>>>>>>> $time_l =3D $row[4];
>>>>>>>>>> $time_h=3D$row[5];
>>>>>>>>>> $location=3D$row[6]; echo "\n
>>>>>>>>>> \n
>>>>>>>>>> \n \n
>>>>>>>>>> \n
>>>>>>>>>> \n
>>>>>>>>>> \n
>>>>>>>>>> \n";
>>>>>>>>>> }
>>>>>>>>>> echo "
BuildingParking LotEstimated Number of Empty SpacesDistance (Feet)Estimated walking time to the building
$building$parking_lot$Number_of_Emp=
ty_Spaces
$Distance$time_h - $time_l mins$location
\n";
>>>>>>>>>> $err=3D1;
>>>>>>>>>> if ($img =3D file_get_contents($location, FILE_BINARY))
>>>>>>>>>> {
>>>>>>>>>> if ($img =3D imagecreatefromstring($img)) $err =3D 0;
>>>>>>>>>> }
>>>>>>>>>> if ($err)
>>>>>>>>>> {
>>>>>>>>>> header('Content-Type: text/html');
>>>>>>>>>> echo '

Error getting
>>>>>>>>>> image...

';
>>>>>>>>>> }
>>>>>>>>>> else
>>>>>>>>>> {
>>>>>>>>>> header('Content-Type: image/jpeg');
>>>>>>>>>> imagejpeg($img);
>>>>>>>>>> imagedestroy($img);
>>>>>>>>>> }
>>>>>>>>>> ?>
>>>>>>>>>>
>>>>>>>>>> /
>>>>>>>>>>
>>>>>>>>>> Sashikanth Gurram wrote:
>>>>>>>>>>
>>>>>>>>>>> Hello guys,
>>>>>>>>>>>
>>>>>>>>>>> Thanks to you all for your kind replies. I will try the steps a=
nd
>>>>>>>>>>> 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 concerne=
d
>>>>>>>>>>>> with
>>>>>>>>>>>> the particulars. Hopefully the concept is sound. If not, pleas=
e do
>>>>>>>>>>>> flame my note so no one attempts it.
>>>>>>>>>>>>
>>>>>>>>>>>> Be Well,
>>>>>>>>>>>> A-
>>>>>>>>>>>>
>>>>>>>>>>>> -----Original Message-----
>>>>>>>>>>>> From: Mattyasovszky Janos [mailto:mail@matya.hu] Sent: Monday,
>>>>>>>>>>>> March
>>>>>>>>>>>> 02, 2009 9:29 AM
>>>>>>>>>>>> To: php-db@lists.php.net
>>>>>>>>>>>> Subject: Re: [PHP-DB] Retrieving Image Location in MySQL
>>>>>>>>>>>>
>>>>>>>>>>>> Fortuno, Adam =EDrta:
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>> //Write a query to pull out the picture's path
>>>>>>>>>>>>> $sql =3D "SELECT path FROM Image WHERE ID =3D %s";
>>>>>>>>>>>>> mysql_real_escape_string($value);
>>>>>>>>>>>>>
>>>>>>>>>>>> Sorry, but this won't work, since you don't map the value of t=
he
>>>>>>>>>>>> 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
>>
>

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