Forum Moderators: open

Message Too Old, No Replies

Storing images in a mysql dbase?

or store the location of the image on my web server?

         

tonynoriega

7:49 pm on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Im not sure quite how to do this, but i am creating a PHP function that will pull images from a database, based on a specific community that my properties are in...

So if "community==='sonata hills'..." then query the database and use the sonatahills.jpg image...

Is that what i need to do? store the location of the image in the dbase table, and put the image on my server?

would anyone have a good link on how to accomplish this?

or a tip?

thanks all...

cmarshall

7:57 pm on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We do this in our wiki.

Just set up a blob or big binary item, and feed the data straight in. Make sure you have a lot of disk space.

If the URI to access the image doesn't change from page load to page load, then the browser cache will handle redraws.

tonynoriega

8:27 pm on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can you do this manually using phpmyadmin?

cmarshall

8:52 pm on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably. If you declare the data as SQL data, then you need to Base64 it so that it becomes text. I don't know if phpMyAdmin allows binary uploads.

We've always done this programatically, so I have no experience in using a text-based admin for this particular purpose (but I use it for all kinds of other stuff).

Duskrider

10:06 pm on Sep 12, 2007 (gmt 0)

10+ Year Member



What I've typically done in this situation is the first way you mentioned. Simply store a location reference in the database and keep the file on the server. I personally find this way easier to manage, and if you ever need the photo for another purpose you don't have to go wading through data to find it.

Usually I make a directory for each type of image (so in your case maybe you create a "communityimages" folder) then name the files the same as their reference in the database... that way I can actually not use a database field to store the image link at all.

I tend to use auto-incrementing id numbers in most of my tables, so all I need to do is use the id for that record in my database as my image filename when it gets uploaded (usually through an upload manager I write... pretty simple). That way in the code I can just have a variable for my standard image location, append the record id, throw on the extension, and presto... there's my file reference. Saves me a field.

$picdirectory = '/images/widgets/';
$imagefile = $picdirectory.$recordid.'.jpg';
echo '<img src="'.$imagefile.'" />';

That's how I do it, but it's just personal preference.