Storing Image Location in MySQL

Storing Image Location in MySQL

am 22.02.2009 09:43:06 von Sashikanth Gurram

Dear All,

I am trying to store the location of a image into MySQL database, so
that I can call it back from PHP to display it in a browser. For this
purpose, I have created a table with two columns (BuildingCode,
Location), where building is the primary key and location is the
location where my picture is stored on my PC. My image is stored at
/C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
The following table is an output from MySQL.
+--------------+-----------------------------------------+
| BuildingCode | Location |
+--------------+-----------------------------------------+
| 176 | c:/users/sashikanth/desktop/burruss.jpg |
+--------------+-----------------------------------------+

Considering my original Image Location on my PC, will the above table be
of any help if I try to retrieve the image using PHP? Is there any
mistake in what I have done till now?
I know that this may be a very basic question and i have searched
through the internet quite extensively but could not find a solid
answer. Would appreciate it greatly if anyone can help.

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: Storing Image Location in MySQL

am 22.02.2009 11:17:30 von Joao Gomes Madeira

Hey Sashi

You want something similar to this:
(you must have GD installed on Apache)

you can have this working by doing something like this in HTML:



and having as picture.php:

.... get the record from the database using query string and then ...

$err=1;
if ($img = file_get_contents('/yourpath/yourfile.jpg', 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);
}
....

Cheers
JP


-----Original Message-----
From: Sashikanth Gurram
To: php-db@lists.php.net
Subject: [PHP-DB] Storing Image Location in MySQL
Date: Sun, 22 Feb 2009 03:43:06 -0500

Dear All,

I am trying to store the location of a image into MySQL database, so
that I can call it back from PHP to display it in a browser. For this
purpose, I have created a table with two columns (BuildingCode,
Location), where building is the primary key and location is the
location where my picture is stored on my PC. My image is stored at
/C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
The following table is an output from MySQL.
+--------------+-----------------------------------------+
| BuildingCode | Location |
+--------------+-----------------------------------------+
| 176 | c:/users/sashikanth/desktop/burruss.jpg |
+--------------+-----------------------------------------+

Considering my original Image Location on my PC, will the above table be
of any help if I try to retrieve the image using PHP? Is there any
mistake in what I have done till now?
I know that this may be a very basic question and i have searched
through the internet quite extensively but could not find a solid
answer. Would appreciate it greatly if anyone can help.

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: Storing Image Location in MySQL

am 22.02.2009 14:48:27 von Phpster

On Feb 22, 2009, at 5:17, Joao Gomes Madeira wrote:

> Hey Sashi
>
> You want something similar to this:
> (you must have GD installed on Apache)
>
> you can have this working by doing something like this in HTML:
>
>
>
> and having as picture.php:
>
> > ... get the record from the database using query string and then ...
>
> $err=1;
> if ($img = file_get_contents('/yourpath/yourfile.jpg', 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);
> }
> ...
>
> Cheers
> JP
>
>
> -----Original Message-----
> From: Sashikanth Gurram
> To: php-db@lists.php.net
> Subject: [PHP-DB] Storing Image Location in MySQL
> Date: Sun, 22 Feb 2009 03:43:06 -0500
>
> Dear All,
>
> I am trying to store the location of a image into MySQL database, so
> that I can call it back from PHP to display it in a browser. For this
> purpose, I have created a table with two columns (BuildingCode,
> Location), where building is the primary key and location is the
> location where my picture is stored on my PC. My image is stored at
> /C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
> The following table is an output from MySQL.
> +--------------+-----------------------------------------+
> | BuildingCode |
> Location |
> +--------------+-----------------------------------------+
> | 176 | c:/users/sashikanth/desktop/burruss.jpg |
> +--------------+-----------------------------------------+
>
> Considering my original Image Location on my PC, will the above
> table be
> of any help if I try to retrieve the image using PHP? Is there any
> mistake in what I have done till now?
> I know that this may be a very basic question and i have searched
> through the internet quite extensively but could not find a solid
> answer. Would appreciate it greatly if anyone can help.
>
> 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

Note that the image needs to be accessible by apache. You may want to
store those images in a folder in or just above the web root and
perhaps create an image upload routine

Bastien

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

Re: Storing Image Location in MySQL

am 22.02.2009 22:47:10 von dmagick

Sashikanth Gurram wrote:
> Dear All,
>
> I am trying to store the location of a image into MySQL database, so
> that I can call it back from PHP to display it in a browser. For this
> purpose, I have created a table with two columns (BuildingCode,
> Location), where building is the primary key and location is the
> location where my picture is stored on my PC. My image is stored at
> /C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
> The following table is an output from MySQL.
> +--------------+-----------------------------------------+
> | BuildingCode |
> Location |
> +--------------+-----------------------------------------+
> | 176 | c:/users/sashikanth/desktop/burruss.jpg |
> +--------------+-----------------------------------------+
>
> Considering my original Image Location on my PC, will the above table be
> of any help if I try to retrieve the image using PHP? Is there any
> mistake in what I have done till now?
> I know that this may be a very basic question and i have searched
> through the internet quite extensively but could not find a solid
> answer. Would appreciate it greatly if anyone can help.

Don't store the full path to the image, just store the relative path.

If you move your app to a new folder, then you have to go through and
update all database records to point to the new path.

If you store the relative path, you can set a config variable (or work
it out yourself), and add the relative path to the end.

So in your config:

$cfg['folder_name'] = 'c:/apps/my_app_name/';

in the db location will be 'images/image.jpg';

Put the two together to get the full path:

$image_path = $cfg['folder_name'] . $db['location'];

--
Postgresql & php tutorials
http://www.designmagick.com/


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

Re: Storing Image Location in MySQL

am 23.02.2009 04:53:23 von Sashikanth Gurram

Thanks fir the suggestion Chris

-Sashi

Chris wrote:
> Sashikanth Gurram wrote:
>> Dear All,
>>
>> I am trying to store the location of a image into MySQL database, so
>> that I can call it back from PHP to display it in a browser. For this
>> purpose, I have created a table with two columns (BuildingCode,
>> Location), where building is the primary key and location is the
>> location where my picture is stored on my PC. My image is stored at
>> /C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
>> The following table is an output from MySQL.
>> +--------------+-----------------------------------------+
>> | BuildingCode |
>> Location |
>> +--------------+-----------------------------------------+
>> | 176 | c:/users/sashikanth/desktop/burruss.jpg |
>> +--------------+-----------------------------------------+
>>
>> Considering my original Image Location on my PC, will the above table
>> be of any help if I try to retrieve the image using PHP? Is there any
>> mistake in what I have done till now?
>> I know that this may be a very basic question and i have searched
>> through the internet quite extensively but could not find a solid
>> answer. Would appreciate it greatly if anyone can help.
>
> Don't store the full path to the image, just store the relative path.
>
> If you move your app to a new folder, then you have to go through and
> update all database records to point to the new path.
>
> If you store the relative path, you can set a config variable (or work
> it out yourself), and add the relative path to the end.
>
> So in your config:
>
> $cfg['folder_name'] = 'c:/apps/my_app_name/';
>
> in the db location will be 'images/image.jpg';
>
> Put the two together to get the full path:
>
> $image_path = $cfg['folder_name'] . $db['location'];
>


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: Storing Image Location in MySQL

am 23.02.2009 04:56:55 von Sashikanth Gurram

Hi JP,

Can you please let me know what is a GD? I have not installed Apache
separately. I am using the WAMP server currently. Do I have to install
any additional stuff before I can retrieve the image location from the
db and display it in my browser?

-Sashi

Joao Gomes Madeira wrote:
> Hey Sashi
>
> You want something similar to this:
> (you must have GD installed on Apache)
>
> you can have this working by doing something like this in HTML:
>
>
>
> and having as picture.php:
>
> > ... get the record from the database using query string and then ...
>
> $err=1;
> if ($img = file_get_contents('/yourpath/yourfile.jpg', 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);
> }
> ...
>
> Cheers
> JP
>
>
> -----Original Message-----
> From: Sashikanth Gurram
> To: php-db@lists.php.net
> Subject: [PHP-DB] Storing Image Location in MySQL
> Date: Sun, 22 Feb 2009 03:43:06 -0500
>
> Dear All,
>
> I am trying to store the location of a image into MySQL database, so
> that I can call it back from PHP to display it in a browser. For this
> purpose, I have created a table with two columns (BuildingCode,
> Location), where building is the primary key and location is the
> location where my picture is stored on my PC. My image is stored at
> /C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
> The following table is an output from MySQL.
> +--------------+-----------------------------------------+
> | BuildingCode | Location |
> +--------------+-----------------------------------------+
> | 176 | c:/users/sashikanth/desktop/burruss.jpg |
> +--------------+-----------------------------------------+
>
> Considering my original Image Location on my PC, will the above table be
> of any help if I try to retrieve the image using PHP? Is there any
> mistake in what I have done till now?
> I know that this may be a very basic question and i have searched
> through the internet quite extensively but could not find a solid
> answer. Would appreciate it greatly if anyone can help.
>
> 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: Storing Image Location in MySQL

am 23.02.2009 04:59:42 von Sashikanth Gurram

Phpster wrote:
>
> On Feb 22, 2009, at 5:17, Joao Gomes Madeira wrote:
>
>> Hey Sashi
>>
>> You want something similar to this:
>> (you must have GD installed on Apache)
>>
>> you can have this working by doing something like this in HTML:
>>
>>
>>
>> and having as picture.php:
>>
>> >> ... get the record from the database using query string and then ...
>>
>> $err=1;
>> if ($img = file_get_contents('/yourpath/yourfile.jpg', 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);
>> }
>> ...
>>
>> Cheers
>> JP
>>
>>
>> -----Original Message-----
>> From: Sashikanth Gurram
>> To: php-db@lists.php.net
>> Subject: [PHP-DB] Storing Image Location in MySQL
>> Date: Sun, 22 Feb 2009 03:43:06 -0500
>>
>> Dear All,
>>
>> I am trying to store the location of a image into MySQL database, so
>> that I can call it back from PHP to display it in a browser. For this
>> purpose, I have created a table with two columns (BuildingCode,
>> Location), where building is the primary key and location is the
>> location where my picture is stored on my PC. My image is stored at
>> /C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
>> The following table is an output from MySQL.
>> +--------------+-----------------------------------------+
>> | BuildingCode |
>> Location |
>> +--------------+-----------------------------------------+
>> | 176 | c:/users/sashikanth/desktop/burruss.jpg |
>> +--------------+-----------------------------------------+
>>
>> Considering my original Image Location on my PC, will the above table be
>> of any help if I try to retrieve the image using PHP? Is there any
>> mistake in what I have done till now?
>> I know that this may be a very basic question and i have searched
>> through the internet quite extensively but could not find a solid
>> answer. Would appreciate it greatly if anyone can help.
>>
>> 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
>
> Note that the image needs to be accessible by apache. You may want to
> store those images in a folder in or just above the web root and
> perhaps create an image upload routine
>
> Bastien
>
Hi Bastien,

I did not quite get what you have said. Does it really matter where we
store the image? I mean, we can always retrieve the location and display
it as long as we feed the db with the correct path. And what is meant by
a image upload routine?

-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: Storing Image Location in MySQL

am 23.02.2009 10:50:54 von Joao Gomes Madeira

Sashi, pls read the following chapter

http://www.php.net/manual/en/book.image.php

Cheers
JP

-----Original Message-----
From: Sashikanth Gurram
To: Joao Gomes Madeira
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Storing Image Location in MySQL
Date: Sun, 22 Feb 2009 22:56:55 -0500

Hi JP,

Can you please let me know what is a GD? I have not installed Apache
separately. I am using the WAMP server currently. Do I have to install
any additional stuff before I can retrieve the image location from the
db and display it in my browser?

-Sashi

Joao Gomes Madeira wrote:
> Hey Sashi
>
> You want something similar to this:
> (you must have GD installed on Apache)
>
> you can have this working by doing something like this in HTML:
>
>
>
> and having as picture.php:
>
> > ... get the record from the database using query string and then ...
>
> $err=1;
> if ($img = file_get_contents('/yourpath/yourfile.jpg', 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);
> }
> ...
>
> Cheers
> JP
>
>
> -----Original Message-----
> From: Sashikanth Gurram
> To: php-db@lists.php.net
> Subject: [PHP-DB] Storing Image Location in MySQL
> Date: Sun, 22 Feb 2009 03:43:06 -0500
>
> Dear All,
>
> I am trying to store the location of a image into MySQL database, so
> that I can call it back from PHP to display it in a browser. For this
> purpose, I have created a table with two columns (BuildingCode,
> Location), where building is the primary key and location is the
> location where my picture is stored on my PC. My image is stored at
> /C:\Users\Sashikanth\Desktop\burruss.jpg/ on my PC.
> The following table is an output from MySQL.
> +--------------+-----------------------------------------+
> | BuildingCode | Location |
> +--------------+-----------------------------------------+
> | 176 | c:/users/sashikanth/desktop/burruss.jpg |
> +--------------+-----------------------------------------+
>
> Considering my original Image Location on my PC, will the above table be
> of any help if I try to retrieve the image using PHP? Is there any
> mistake in what I have done till now?
> I know that this may be a very basic question and i have searched
> through the internet quite extensively but could not find a solid
> answer. Would appreciate it greatly if anyone can help.
>
> Thanks,
> Sashi
>
>




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