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

x
  • 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!!!
thanks!
0
ysloo
Asked:
ysloo
2 Solutions
 
anandkpCommented:
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

K'Rgds
Anand
0
 
TallerMikeCommented:
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#
</cfquery>

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">
<cfoutput>#imageObj#</cfoutput>

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.
0
 
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!

rgds,
ys
0
Get your problem seen by more experts

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

 
anandkpCommented:
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

K'Rgds
anand
0
 
anandkpCommented:
hello ??????????
0
 
mrichmonCommented:
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.

mrichmon
EE Cleanup Volunteer
0

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