> I am working on some forms that will be used for inserting/
> editing data in my database. On one of the forms I need to 
> upload a file and provide the INSERT statement with a filename 
> for my database. I have it working using 2 fields; 1 for the 
> file I wish to upload and 1 for the file name I wish to insert 
> into my database. I currently have to copy and paste the file 
> name from the file path to the file name field.
> 
> I was wondering how I might be able to do this more efficiently. 
> Is there a way the get the file name from the input type="file" 
> so I can use it in my SQL statement? I know that once the form 
> is submitted a <cfoutput>#form.file#</cfoutput> would yield 
> something like C:\WINNT\TEMP\ACF12D.tmp. If it's not possible, 
> am I going about it in the same manner as most folks?

After you process the file upload with CFFILE ACTION="UPLOAD", you'll have a
bunch of variables available to you in the File scope:

attemptedServerFile
 Initial name ColdFusion used when attempting to save a file 
 
clientDirectory 
 Directory location of the file uploaded from the client's system 
 
clientFile 
 Name of the file uploaded from the client's system 
 
clientFileExt
 Extension of the uploaded file on the client's system without a period, for
example, txt not .txt 
 
clientFileName
 Filename, without an extension, of the uploaded file on the client's system

 
contentSubType
 MIME content subtype of the saved file
 
contentType
 MIME content type of the saved file
 
dateLastAccessed 
 Date and time the uploaded file was last accessed
 
fileExisted
 Indicates (Yes or No) whether or not the file already existed with the same
path 
 
fileSize 
 Size of the uploaded file 
 
fileWasAppended 
 Indicates (Yes or No) whether ColdFusion appends the uploaded file to an
existing file 
 
fileWasOverwritten
 Indicates (Yes or No) whether ColdFusion overwrites a file 
 
fileWasRenamed 
 Indicates (Yes or No) whether the uploaded file is renamed to avoid a name
conflict 
 
fileWasSaved 
 Indicates (Yes or No) whether Cold Fusion saves a file 
 
oldFileSize
 Size of a file that was overwritten in the file upload operation 
 
serverDirectory
 Directory of the file saved on the server 
 
serverFile 
 Filename of the file saved on the server 
 
serverFileExt 
 Extension of the uploaded file on the server, without a period 
 
serverFileName
 Filename, without an extension, of the uploaded file on the server 
 
timeCreated 
 Time the uploaded file was created 
 
timeLastModified
 Date and time of the last modification to the uploaded file 

(I copied this straight from the docs, which explains the slightly funky
formatting.)

So, you could look at File.ClientFile to see what name the file had on the
user's machine, and File.ServerFile to see what name it has on the server
(assuming you're using NAMECONFLICT="MAKEUNIQUE" in your CFFILE tag to
prevent duplicate file names). 

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to