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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the name of a file I have just uploaded?

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
Hi Everyone,<br><br>I have figured out how to upload a file into the directory of my choice.&nbsp;&nbsp;My problem now, is how do I get the name of the file into a database?&nbsp;&nbsp;I want the user to fill out a form with their name, a description of the file etc. and then submit the file.&nbsp;&nbsp;When I list the files in the db, I want to be able to view the name, description (etc) and then click on the link to the file.&nbsp;&nbsp;How do I store the name of the file in the db without having the user enter it twice?&nbsp;&nbsp;&nbsp;I can get the file name after it has been uploaded by using #File.ClientFile#, but I can't figure out how to get that value into my db.&nbsp;&nbsp;(I'm very new to this stuff!!) Here is my code so far:<br><br>uploaddocument.cfm<br><br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;TITLE&gt;Specify File to upload&lt;/TITLE&gt;<br>&lt;/HEAD&gt;<br><br>&lt;BODY&gt;<br>&lt;H2&gt;Specify File to upload&lt;/H2&gt;<br>&lt;FORM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ACTION=&quot;fileuploadaction.cfm&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENCTYPE=&quot;multipart/form-data&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;METHOD=&quot;post&quot;&gt;<br> <br>Document Description: &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;DocDescription&quot; SIZE=&quot;50&quot; MAXLENGTH=&quot;100&quot;&gt;&lt;br&gt;<br>Submitted By: &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;DocSubmitter&quot; SIZE=&quot;50&quot; MAXLENGTH=&quot;100&quot;&gt;<br>&lt;P&gt;Enter the complete path and filename of the file to upload:<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;INPUT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPE=&quot;file&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME=&quot;Filetoupload&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SIZE=&quot;25&quot;&gt;<br>&lt;/P&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;INPUT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPE=&quot;submit&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VALUE&quot;upload&quot;&gt;<br>&lt;/FORM&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br><br>fileuploadaction.cfm<br><br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;TITLE&gt;upload File&lt;/TITLE&gt;<br>&lt;/HEAD&gt;<br><br>&lt;body&gt;<br>&lt;H2&gt;upload File&lt;/H2&gt;<br><br>&lt;CFFILE ACTION=&quot;upload&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DESTINATION=&quot;c:\inetpub\ DATASOURCE=&quot;virtualmanager&quot; TABLENAME=&quot;docs&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br>&lt;CFOUTPUT&gt;<br>You uploaded the file #File.ClientFile# <br>successfully.<br>&lt;/CFOUTPUT&gt;<br><br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br><br>Thank you so much to whoever can help me!!<br>
 
Instead of the &lt;cfinsert&gt; try:<br><FONT FACE=monospace><b><br>&lt;cfquery name=&quot;insert&quot; datasource=&quot;virtualmanager&quot;&gt;<br>insert into docs (DocSubmitter,DocDescription,FileName)<br>values ('#form.DocSubmitter#','#DocDescription#','#file.ClientFile#')<br>&lt;/cfquery&gt;<br></b></font><br>You can output this like:<br><FONT FACE=monospace><b><br>&lt;cfquery name=&quot;docs&quot; datasource=&quot;virtualmanager&quot;&gt;<br>select * from docs<br>&lt;/cfquery&gt;<br><br>&lt;cfoutput query=&quot;docs&quot;&gt;<br>&nbsp;&nbsp;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;<A HREF=" TARGET="_new"> - #DocDescription#&lt;br&gt;<br>&nbsp;&nbsp;&lt;i&gt;Submitted by #DocSubmitter#&lt;/i&gt;&lt;/p&gt;<br>&lt;/cfoutput&gt;<br></b></font><br>Hope this helps...
 
Darkman - you are my hero.&nbsp;&nbsp;:)<br><br>Thanks so much!&nbsp;&nbsp;<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top