Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Post picture to keep in database.

hi experts,

i'm very new in creating a web page using coldfusion(to link to database) and dreamweaver( as the interface). i need to do one function that can let the user to post their picture through the web page and keep in the database.can tell me how to do it?Please help!!!
2 Solutions
hi this is easy,

allow the user to upload the picture to a particular dir - say "root/userimages/myphoto.jpg"

now just insert teh value [as text] "myphoto.jpg" in the DB

when referring to the image for this particular user ... call the record from the DB - using his userid & read the column that stores teh imagename

displayt eh image as http://urdomain.com/userimages/#query.Imagecolumn#

let me know

I agree with anand, storing the picture in the DB itself is NOT the best method. Saving it on the server is probably going to be easier, then you just store the location on the server of the image and output it as he said.


When you store an image in the DB, it's in a BLOB type field. The trick to this isn't storing the image, it's retrieving it in a usable fashion. What you'd need to do is to have a call like so:

<img src="userImage.cfm?imageID=8675309" />

Then on userImage.cfm:

<cfquery name="qImage" datasource="Jenny">
  SELECT imageObj
  FROM imageTable
  WHERE imageID = #url.imageID#

From here, there's 2 places you can then go. Either way, you'll use CFCONTENT to setup the correct MIME type (image/gif or something like that) for the download.

One method is to simply output the imageObj like so:

<cfcontent type="image/gif">

But the preferred method is to write the image to a file on the web server, and THEN cal CFCONTENT with the path of the image like so:

<cfcontent type="image/gif" deleteFile="Yes" file="#fileLocation#">

Where fileLocation is the full URL of where you wrote the image file from the DB.


So what's to learn from this? Well, in the end (in the preferred method), you ended up writing the image to the disk anyhow, so it may as well have already been there. It would have been faster and more stable.
yslooAuthor Commented:
hi experts,
thanks for helping me!
however i not really get what u guys mean.i'm really slow in learning these thing.what i understand now is not storing pictures in DB.
is that i need to create a folder in my web server to write the images?do i still need to create a DB(table) for pictures/images?
please help!thanks again!

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

yes - ur getting it right

create a folder called userimages on server & save all the images that the user wld upload in there

also have a DB-table where u can insert records of users - but just store the image name in there - so its easier for u to read/write

follow the instructions in my first comment & that shld be it

hello ??????????
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Split anandkp & TallerMike

Please leave any comments here within the next four days.

EE Cleanup Volunteer

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now