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

Adding a file to database using cffile 1

Status
Not open for further replies.

dnml

Technical User
Mar 4, 2003
7
AU
Hi,

I want to allow a user to browse for a file and then upload that file into a database field.

What I have so far: I have set up a form where a user is required to enter a number of attributes in input boxes. The form enctype has been set to “mulipart/form-data” and I have a file type input where the user browses for the file they want to upload.

I then have a second page that is called when the user submits the first page. I have set up an SQL insert statement that populates the database with the attributes entered by the user. What I now need to do is to rename the uploaded file based on some of the entered attributes and insert into the database.

I have looked at the cffile tag but have not had any success with it so far. Does anyone have any tips and pointers for doing this?

The file I want to insert into the database is #Form.File# and I am using MySQL with a BLOB field named Upload_Object.

Thanks in advance.

Dan
 
Here is the upload:

<cffile action=&quot;upload&quot;
filefield=file <--This may be a conflict
destination=&quot;E:\inetpub\ nameconflict=&quot;overwrite&quot; <-- Will overwrite existing file with same name
mode=&quot;777&quot;> <-- Set your CHMOD permissions here

Then you can rename in a move:

<cffile action=&quot;move&quot;
source=&quot;E:\inetpub\
destination=&quot;E:\inetpub\attributes=&quot;normal&quot;>

In the move, you can change the path also to a different directory if needed.

The #File.ClientFileExt# will keep the file with the same extension. You could however put .txt for example to change all files to text files. Depends on what your uploading. There is also an &quot;allow&quot; param of the cffile tag to limit upload. If this application is open to the public, USE IT!



DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 

One more thing. Your storing the file on the server and writing the path to the file in the database.

<cfquery name=&quot;add_formname&quot; datasource=&quot;#application.ds#&quot;>

insert into xxxxx (Upload_Object)

values ('#form.file#')

</cfquery>

Pretty hard on the database to store the file in it.


DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top