Start New Discussion Reply to this Discussion Image Upload Help
Hi everyone. I have not done any type of coding in some years and can use some help with a simple yet frustrating task. I am trying to allow registered users to upload a "profile" photo to the server and insert the path into the database. I would like to do this as a "record update" in coldfusion with the session variable MM_Username as the primary key. Can someone please help me with a code sample.
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Arrgh... the site ate my response. Anyway, that's a sql UPDATE. The basic syntax is:
http://www.w3schools.com/SQl/sql_update.asp
<cfquery ...>
UPDATE TheTableName
SET ImagePathColumnName = <cfqueryparam value="#variableWithPath#"
cfsqltype="(your type here)">
WHERE PrimaryKeyColumn = <cfqueryparam value="#variableWithPrimaryKey#"
cfsqltype="(your type here)">
</cfquery>
If you need specifics, post your table structure and form code.
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0
Thanks this is what I was able to use:
<cfupdate datasource="pReport"
tablename ="tblAdmins"
formfields="Image, user_name">
my problem was catching the file name which I was able to do by inserting a hidden field with the value of #file.serverfile#
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Ok, I didn't know that was your issue. Glad you figured it out. Just one thing - #FILE# is deprecated. Use #CFFILE.serverFile# instead.
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0
Thank you very much I will make that change.
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
One last question if I may, I am using this CFIF statement to display an image if a record exists in the db or to hide it if no record exists.
<cfif rsProfile.Image GT 0>
<img src="<cfoutput>rs.image</cfoutput>"/>
</cfif>
This works perfectly fine in IE and Chrome however in FF it doesn't display the image even if the record does exist.
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Aside from missing # signs around your variable, I'm not sure why it doesn't work.
What's the value of #rs.Image#? It should be a valid URL like:
/mysite/path/to/myImage.png
../images/myImage.png
myImage.png
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0
Yes it actually reads:
<cfif rsProfile.Image GT 0>
<img src="<cfoutput>#rsProfile.Image</cfoutput>#"/>
</cfif>
This one is strange to me since FF is the only browser that I am having an issue with.
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
The # signs are still off. But I'm guessing it's just a copy paste error, or you'd be getting a syntax error.
Anyway, you didn't answer my question. What's the actual value of #rsProfile.Image#?
The value of rsProfile.Image = <cfoutput>#rsProfile.Image#</cfoutput><br />
<!--- check the length, not the value --->
<cfif len(trim(rsProfile.Image))>
<cfoutput><img src="#rsProfile.Image#" /> </cfoutput>
</cfif>
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0
Sorry it has taken me so long to reply. I spent the last 3 days trying to figure out what the problem was and it was a very simple simple fix that I am embarassed about. I was using "\" when I needed "/". :(
Thanks for all of your time and help.
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
It happens. That is why I suggested printing out the value. Don't feel bad, I once spent an hr chasing my tail only to find out the problem was extra white space. Kept thinking I was right about the code, lol. Didn't figure out my mistake until I went character by character.. Lesson learned ;-)
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0
LOL I guess it happens. I thought it was just me.
cee.gee.50
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
ROFL .. I wish! Too bad code always does what we tell it to do, instead of what we want it to do ;-)
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0958 seconds
using 2.71MB