• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trouble uploading file with specific filename

Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 06, 2008 Nov 06, 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/

Votes

Translate

Translate
Guest
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.)

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

tgoold wrote:
> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

Sorry, I forgot to answer your question completely.
"not working" means that the file is not being uploaded to the database.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

you are NOT uploading any files to use <cffile action="upload">!

you need action="write" instead.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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 :

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 07, 2008 Nov 07, 2008

Copy link to clipboard

Copied

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#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 10, 2008 Nov 10, 2008

Copy link to clipboard

Copied

LATEST
Thank you all for helping on this. It works now!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation