Skip to main content
Inspiring
December 14, 2009
Question

Upload Files to MySQL

  • December 14, 2009
  • 1 reply
  • 2237 views

I have some code where I'm uploading different file types to my server. This works great. However, I'm trying to upload the file name to the MySQL database but I can't seem to get it to go. Any help on this would be greatly appreciated. Thanks.

My Code:

<CFSET FileDir = ExpandPath("..\manage\users\#acct#\#fileLoc#\")>

<cffile action="upload" destination="#FileDir#" filefield="fileUPLOAD" nameconflict="overwrite" result="Upload">

<cffile ACTION="Read" FILE="#FileDir#" variable="FileData">
  
<cfquery name="UploadFile" datasource="#db#">
    INSERT INTO documents (User_ID, title, file_name)
    VALUES (#FORM.UserID#, '#FORM.title#', <cfqueryparam cfsqltype="cf_sql_varchar" value="#FileData#"> )
</cfquery>  

This topic has been closed for replies.

1 reply

Inspiring
December 14, 2009

You say you want to store the file name, but your code shows you trying to store the contents.  The file name gets generated during the upload process.  Cfdump your upload variable and see if it contains anything useful.

Inspiring
December 14, 2009

I don't see anything, just outputs a the name of the field. I don't have anything useful on this.

I am trying to capture the filename and I have a seperate field where they type in a better name for the file they are uploading.

ilssac
Inspiring
December 14, 2009

<cffile action="upload" destination="#FileDir#" filefield="fileUPLOAD" nameconflict="overwrite" result="Upload">

<cfdump var="#Upload#">

This doesn't show you anything interesting?