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) ?

Recommended Answers

All 3 Replies

Member Avatar

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.

Member Avatar

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.

commented: Made an account just so I could upvote this post, fantastic idea. Thank you! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.