Re: [PHP-DB] Storing Image Location in MySQL
[email protected] (Chris)
| Newsgroups | php.db |
|---|---|
| Message-ID | <[email protected]> |
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/