Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Upload to Database 1

Status
Not open for further replies.

bobbyr

Programmer
Nov 30, 2000
66
0
0
US
I'm having a little problem. I'm submitting a form that includes a person's name(type=text), number(type=text), and photo(type=file). I currently have all the fields being inserted into the database and working fine, except the file. The upload is working, but I can't seem to parse the filename and store only the "photo.jpg" part in the database. The form is set as enctype="multipart/form-data" for the file upload. Any suggestions?? Thanks in advance!

Bobby
 
AGGHH!! I just found the answer to this question after an extensive search on this forum. Thanks anyways!
 
Would you share the fix, or say what post helped??

Thanks.
 
<--- I created my form to insert a new player into my hockey database. What I wanted to do was upload a photo of the player at the time I was inserting his generic data (ie. Name, Jersey Number, Position Id). Notice I used enctype=&quot;multipart/form-data in the form tag so that the file would upload. --->

<form action=&quot;insertplayer.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>

Add a new player:
<input type=&quot;text&quot; name=&quot;JerseyNumber&quot; maxlength=&quot;3&quot;>

Position:
<select name=&quot;PositionId&quot;>
<cfoutput query=&quot;getpositions&quot;>
<option value=&quot;#PositionId#&quot;>#PositionName#</option>
</cfoutput>
</select>

Player Name:
<input type=&quot;text&quot; name=&quot;Name&quot; maxlength=&quot;50&quot;>

Photo:
<input type=&quot;file&quot; name=&quot;Photo&quot;>

<input type=&quot;submit&quot; value=&quot;Add Player&quot;>
</form>


<--- This is the action page that inserts generic player data from the form. The first thing I do is upload the image file from the form. --->

<CFFILE ACTION=&quot;Upload&quot; FILEFIELD=&quot;Photo&quot; DESTINATION=&quot;e:\sitedir\photos\&quot; NAMECONFLICT=&quot;MakeUnique&quot;>


<--- Here, I insert the form data into the database. Notice I used #file.clientfile# to request the file name of the photo. This is the problem I was having. By not using #file.clientfile#, I was getting a &quot;filename.tmp&quot; entry in the database. -->


<cfquery name=&quot;insert&quot; datasource=&quot;dsn&quot;>
insert into team (PositionId, JerseyNumber, Name, Photo)
values
('#Form.PositionId#','#Form.JerseyNumber#',
'#Form.Name#','#file.ClientFile#')
</cfquery>

I couldn't find the post that taught me this again. I'll keep searching and post it again as soon as I do. Special thanks to whoever posted it though!
 
Here's the post that taught me the trick... Sorry for buggin out the forum with my weird post above...


DarkMan (Programmer) Jul 18, 2000
Instead of the <cfinsert> try:

<cfquery name=&quot;insert&quot; datasource=&quot;virtualmanager&quot;>
insert into docs (DocSubmitter,DocDescription,FileName)
values ('#form.DocSubmitter#','#DocDescription#','#file.ClientFile#')
</cfquery>

You can output this like:

<cfquery name=&quot;docs&quot; datasource=&quot;virtualmanager&quot;>
select * from docs
</cfquery>

<cfoutput query=&quot;docs&quot;>
<p><b><a href=&quot; - #DocDescription#<br>
<i>Submitted by #DocSubmitter#</i></p>
</cfoutput>

Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top