hey guys. so first of im kinda confused as to which forum i should post to but i hope you guys arent mad if this isnt the appropriate forum.
moving on, i have these bunch of images that i want to be able to be displayed after a button click but before i start coding that im not sure how to store the images, should i store image file paths into database (if so how do i do that? google-ing, i only found the kind that uploads an image from a website by a user then stored in database but what i would like is images that are already stored in the database then retrieved after button click) or the image itself(but from what i gathered that method isnt the best) or should i have an <img> tag with style="visibility:hidden"(if i do this i work with javascript instead) ?

3 Years
Discussion Span
Last Post by diafol

I suggest you store the image filename - possibly without path if images are all stored in the same location - that way you don't have to change all the filepaths if you decide to move locations. Usually these records are created on successful image upload.

For retrieval, you'd simply get the filename from the DB, prepend with the path and place into an img tag.

Of course, you could store the image itself in a blob field and base64 it as output - but that's a bit fiddly and I've never been convinced that's the best method anyway.


I use phpmyadmin to create my database. so if my images are in a file named 'images' and there is one image with the name="logo.jpg", in the name column of phpmyadmin do i put: "images/logo.jpg", and type:"VARCHAR", do i define the MIME type as Image/JPEG and Browseer transformation as image/jpeg:link as well? or is that not the way to do it?
coz i found this site http://bytes.com/topic/mysql/answers/903540-how-store-images-database-using-path-filename (answered question by curtis mattoon)
but im still not sure.


I'd just use

logo.jpg in the field - not the 'images' folder, because you may wish to change the move or rename the folder at some point and then you'd have to update every record in the DB. Not so difficult maybe, but much easier if you hardcode the image location in php, e.g.


Your image could then be...

<img src="<?php echo IMAGE_DIR . $row['image'];?>" />

If you've stored the images in the 'image' field of your table.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.