Skip to main content
Inspiring
November 6, 2008
Answered

Trouble uploading file with specific filename

  • November 6, 2008
  • 16 replies
  • 1474 views
I have built a gui that allows the user to enter a news release (using IRite for editing) and have it upload to the server. It needs to be uploaded to the server using a specific name, which the user selects from a drop-down. It's not working and I'm not sure why. Can someone take a look at my code and see if they can spot something? Thanks.
This topic has been closed for replies.
Correct answer Newsgroup_User
assuming, as in your original post, you are using a textarea with
NAME="newsrelease" for text input, all you need is:

<cffile action="write" destination="#expandpath('..\news\') &
form.filename#" output="#form.newsrelease#">

if your drop-down filename box contains only the name part and no
extension (i.e. "mynews" instead of "mynews.cfm"), then add & '.cfm'
after form.filename in the destination attribute of cffile tag above.


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

16 replies

tgooldAuthor
Inspiring
November 10, 2008
Thank you all for helping on this. It works now!!
Inspiring
November 7, 2008
tgoold wrote:
> It sounds like cffile only writes a text file. Is it even possible to write a
> cfm file? Or is there a step I can do to turn the text file into a cfm file?
>

A cfm file *is* a text file. It is not a binary file, the opposite of a
text file.

The process you are stumbling around with here should look something
like this.

Collect data from your database and form and build the file content into
a variable. <cfsavecontent....> is very handy for this, but not required.

Write that variable to a file with the <cffile action="write"
file="path/to/root/someFile.cfm" output="#contentVariable#">
Newsgroup_UserCorrect answer
Inspiring
November 7, 2008
assuming, as in your original post, you are using a textarea with
NAME="newsrelease" for text input, all you need is:

<cffile action="write" destination="#expandpath('..\news\') &
form.filename#" output="#form.newsrelease#">

if your drop-down filename box contains only the name part and no
extension (i.e. "mynews" instead of "mynews.cfm"), then add & '.cfm'
after form.filename in the destination attribute of cffile tag above.


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
tgooldAuthor
Inspiring
November 7, 2008
I don't think this is still quite what I'm looking for. Here's what it says about cffile in the Knowledgebase on Adobe.

cffile action = "write"
View comments | RSS feed

Description

Writes a text file on the server, based on dynamic content. You can create static HTML files from the content, or log actions in a text file.

It sounds like cffile only writes a text file. Is it even possible to write a cfm file? Or is there a step I can do to turn the text file into a cfm file?
tgooldAuthor
Inspiring
November 7, 2008
Ok, I changed the action back to upload. What's happening now is that my drop down box has not effect (no submit button) and there's a browse field and button underneath it. That won't work, because the file hasn't been created yet so I can't browse for it.
Inspiring
November 7, 2008
> I've changed the input type to "file" and changed the "upload" to "write".

If you _are_ using a file field (ie <input type="file" ...>) the action should be UPLOAD.
tgooldAuthor
Inspiring
November 7, 2008
I'm not moving to another page. It's all done on the same page. I write the news release in one field and pick out the filename from a drop down on the same page.
tgooldAuthor
Inspiring
November 7, 2008
ok, so I've changed the input type to "file" and changed the "upload" to "write". Now I get this error message.

When the value of the ACTION attribute is "WRITE", the tag requires the attribute(s): FILE,OUTPUT.

The error occurred in E:\webdata\website\tax\anewtaxsite\gui\g-add-news2.cfm: line 105

103 : <cfelse>
104 : <cfif isDefined("newsrelease")>
105 : <cffile destination="#getDirectoryFromPath(getBaseTemplatePath())#..\news\#filename#" action="write" nameConflict="overwrite" filefield="fileName" ></cfif>
106 : </cfif></cfif>
107 :
Inspiring
November 7, 2008
If you really do mean upload a file from the user's browser, you need to use an input field with type "file".

<input type="file" name="yourFieldName" ....>

It must be uploaded on the same page it is submitted to. In other words, you cannot submit the file to ActionPage1, move on to another form, and perform the upload later. It must be processed on ActionPage1.

Inspiring
November 6, 2008
> take the text that I've written in the form and turn it into a cfml file?

You mean take content from a form (or database) and save it to a cfm file on the server? For that you use <cffile action="write" ...>. The upload action is used for uploading files (images, etcetera) from a user's browser to your server.