This content has been marked as final. Show 16 replies
I think the "filefield" parameter is valid only for actual file fields (input type=file). For this you should use the actual filename (<cffile file="#filename#"...>.
(On second thought the file= parameter doesn't work when action=upload - I believe you actually have to have a file field to allow the user to browse for the file. Otherwise the server can't access the file on the client. Looking at this closer, what you need is both the file selection field (for the destination name) and an input of type=file (to select the file on the client). The file on the client doesn't have to be named the same as the selected destination.)
So are you saying that I can't take the text that I've written in the form and turn it into a cfml file?
> It's not working
Help us out here ;-) What does "not working" mean? What it is actually happening versus what you expect to happen. If you are receiving an error, post the error message.
Here's what I've got set up. A two step process.
First page collects information that writes to a database, which includes a filename.
Second page. Has an area that the user can type in a news release and also a drop down that they select a filename (which they entered into the database on the previous page).
I want the app to upload the news release in cfm format to the web server, using the filename that I selected from the drop down box. I took snapshots of what the interface looks like, but don't see a place to attach them. I thought it would help you understand what I'm trying to do.
Sorry, I forgot to answer your question completely.
"not working" means that the file is not being uploaded to the database.
> 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.
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.
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>
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.
> 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.
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.
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
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?
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\') &
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.
> 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
The process you are stumbling around with here should look something
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"
Thank you all for helping on this. It works now!!