Solved

how do you upload a file in coldfusion.

Posted on 2013-05-23
23
419 Views
Last Modified: 2013-07-24
My code seem to be working on my older coldfusion server.

So I've moved my project to a different server.  When I click on the import-file button i'm having an error on line 60.

This is my line of code #60:

<!--- old one didn't work --->
<!--- <CFFILE ACTION="read" FILE="#application.directory_path#\members\toolkit\import\#parsed_file_name#" variable="qrydata">--->
       
<!---This is the new one it's working I can browse for the file  --->
    <CFX_SFILE USERNAME="xxxxxx" PASSWORD="xxxxxx"  ACTION="read" FILE="#application.directory_path#\members\toolkit\import\#parsed_file_name#" variable="qrydata">

When I select the file I got a coldfusion error what this mean.
This is the errors.

Error processing CFX custom tag "CFX_SFILE". The CFX custom tag "CFX_SFILE" was not found in the custom tag database. Please be sure to add custom tags to the database before using them. If you have added your tag to the database then you should check the spelling of the tag within your template to insure that it matches the database entry. <br>The error occurred on line 61.
import-file.jpg
errors.jpg
0
Comment
Question by:koila
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
  • 4
  • +1
23 Comments
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 39192079
Uploading an file is a very simple thing with Coldfusion.

<cfif isDefined("fileUpload")>
  <cffile action="upload"
     fileField="fileUpload"
     destination="C:\docs">
     <p>Thankyou, your file has been uploaded.</p>
</cfif>
<form enctype="multipart/form-data" method="post">
<input type="file" name="fileUpload" /><br />
<input type="submit" value="Upload File" />
</form>
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 39192090
Looks like your new server is missing custom coldfusion tag

CFX_SFILE

 ColdFusion Extension (CFX) tags are custom tags that you write in Java or C++. Generally, you create a CFX tag to do something that is not possible in CFML. CFX tags also let you use existing Java or C++ code in your ColdFusion application.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39192619
(no points ...)

For it to work, you need to register that custom tag on your new server.  Find the DLL (C++ tag) or .class file (java tag) for the custom tag and register it in the CF Administrator.

For instructions, see Building Custom CFXAPI Tags :
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=CFXTags_4.html
0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 39193419
if you want o use same tag, Follow Suggestion of _agx, else check Pravinasar's file  Functionality,

If you need additional features in Uploading check this tutorial

http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/A_2888-Uploading-a-File-in-Coldfusion.html
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 39194314
I suspect the custom tag was meant for multiple file upload.

Since CF9, mutliple file upload functionality is available.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec18238-7fd0.html
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39194525
@pravinasar - I did a quick search and found very few references. This one says a specific host used it for security reasons under CF5 - and that it doesn't work in CF6+.


For Primus servers running Coldfusion 5, Primus has determined that the security model which is build into Coldfusion 5.0 is not suitable for a shared hosting environment. .. for security purposes, Primus has disabled the CFFILE, CFDIRECTORY, and CFFTP tags on the UNIX servers running Coldfusion 5.0. Primus has developed a number of secure custom Coldfusion tags for Coldfusion 5.0 that provide similar functionality. ... These tags are not available on servers running Coldfusion MX.


@koila - Did you switch hosts too? What version of CF are you running?
0
 
LVL 4

Author Comment

by:koila
ID: 39194745
yes, I've switch the hosts too. I will found out from the provider.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39194845
There's a comment in the OP about cffile: "old one didn't work".  Does CFFILE work on your new host?

You can check your version by dumping the server scope, under "coldfusion":

      <cfdump var="#server#">
0
 
LVL 29

Assisted Solution

by:Pravin Asar
Pravin Asar earned 334 total points
ID: 39194965
On my server, to help me quickly identify the issues, I use test code.

Here it is

<cfoutput>
<h1>HOST NAME: #GetHostPath()#</h1>
<h1>HOST ROOT DIR: #ExpandPath("/")#</h1>
</cfoutput>
<h1>CGI VARIABLES</h1>
<!--- Get CGI Variable --->
<cfdump var="#CGI#"/>
<!--- Get HTTP Variables --->
<h1>HTTP VARIABLES</h1>
<cfdump var="#HTTP#"/>
<cfscript>
function GetHostPath() {
      hostname=cgi.http_host;
      if (cgi.https_on is "on") {
            hostname= 'https://' & hostname;
      }
      else {
            hostname= 'http://' & hostname;
      }
      return hostname;
}
</cfscript>
<cfoutput>This is a Server and Session Information</cfoutput>

<h1>CF Server Information</h1>
<cfdump var="#server#">

<h1>Session Information</h1>
<cfdump var="#session#">
0
 
LVL 4

Author Comment

by:koila
ID: 39195003
how i'm able to convert this to cf_file.


<CFX_SFILE USERNAME="xxxxxx" PASSWORD="xxxxxx"  ACTION="read" FILE="#application.directory_path#\members\toolkit\import\#parsed_file_name#" variable="qrydata">
0
 
LVL 4

Author Comment

by:koila
ID: 39195007
I will have to review the coldfusion with the admin person.

or I should create a .cfm file and run this code in the ie browser. I will have to add my domain name right? to the http://www.xxxx.com

<cfoutput>
<h1>HOST NAME: #GetHostPath()#</h1>
<h1>HOST ROOT DIR: #ExpandPath("/")#</h1>
</cfoutput>
<h1>CGI VARIABLES</h1>
<!--- Get CGI Variable --->
<cfdump var="#CGI#"/>
<!--- Get HTTP Variables --->
<h1>HTTP VARIABLES</h1>
<cfdump var="#HTTP#"/>
<cfscript>
function GetHostPath() {
      hostname=cgi.http_host;
      if (cgi.https_on is "on") {
            hostname= 'https://' & hostname;
      }
      else {
            hostname= 'http://' & hostname;
      }
      return hostname;
}
</cfscript>
<cfoutput>This is a Server and Session Information</cfoutput>

<h1>CF Server Information</h1>
<cfdump var="#server#">

<h1>Session Information</h1>
<cfdump var="#session#">
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 166 total points
ID: 39195040
You only need one line of CF code to check the version:

        <cfdump var="#server#">

To convert the custom tag stuff to cffile, try the code in pravinasar's first post:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_28137293.html#a39192079
0
 
LVL 4

Author Comment

by:koila
ID: 39205274
I got this error:

The form field "fileUpload" did not contain a file.  <br>The error occurred on line 64.

This is my code:

  <cffile action="upload"
     fileField="fileUpload"
     destination="#application.directory_path#\members\toolkit\import\#parsed_file_name#">


<!--- My old code --->        
<!--- Start
            <CFFILE ACTION="upload" FILE="#strAttachment#" nameconflict="OVERWRITE" DESTINATION="#application.directory_path#\members\toolkit\import\#parsed_file_name#">
                  End --->
0
 
LVL 4

Author Comment

by:koila
ID: 39205278
This is overview of my code.
<cfif xaction eq "submit">
	<!---Check for submission errors--->
	<cfif strAttachment eq "">
		<cfset strAttachment_err = "Y">
		<cfset err = "Y">
	</cfif>
	
	<cfif err eq "N">
		<!---Process file to import--->
		<cfif form.strAttachment neq "">
			<!---Get the file name from the path--->
			<cfset parsed_file_name = #GetFileFromPath(form.NameHidden)#>
			
			<!---Upload the file--->   
            <!--- My old code --->         
			<!--- Start
            <CFFILE ACTION="upload" FILE="#strAttachment#" nameconflict="OVERWRITE" DESTINATION="#application.directory_path#\members\toolkit\import\#parsed_file_name#">
			End --->
            

  <cffile action="upload"
     fileField="fileUpload"
     destination="#application.directory_path#\members\toolkit\import\#parsed_file_name#">


            
           <!--- <CFX_SFILE USERNAME="actca" PASSWORD="Mex" ACTION="upload" FILE="#strAttachment#" nameconflict="OVERWRITE" DESTINATION="#application.directory_path#\members\toolkit\import\#parsed_file_name#">--->

            
          
		
			<!---Read the file--->
			<CFFILE ACTION="read" FILE="#application.directory_path#\members\toolkit\import\#parsed_file_name#" variable="qrydata">
            <!---<CFX_SFILE USERNAME="actca" PASSWORD="Mex"  ACTION="read" FILE="#application.directory_path#\members\toolkit\import\#parsed_file_name#" variable="qrydata">--->
            
			<!---Loop through the file to set teh data variable--->
			<cfset data = "">
			<cfloop query="qrydata">
				<cfset data = "#Trim(data)#
#line#"></cfloop>

Open in new window

0
 
LVL 4

Author Comment

by:koila
ID: 39208187
AGX, what do you think how i'm able to fix this issue.
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 39208756
Koila,

Here is a simple sample code for multiple file uploads.

Meanwhile I will dig into your posted code, to point out the issues.


<!--- FILE: FILEUPLOAD.CFM --->

<cfform name="f1"  method="post" action="processfiles_action.cfm">
      <table cellpadding="20" cellspacing="20" width="800">
            <tr>
                  <th>
                        <cffileupload url="uploadfile_action.cfm" width="750" height="600"  maxuploadsize="10" bgcolor="##d7c19f"/>
                  </th>
            </tr>
            <tr>
                  <th style="text-align:right;">
                        <cfinput type="submit" name="submit" value="Submit" />
                  </th>
            </tr>
      </table>
</cfform>
<cfexit>

<!--- FILE: uploadfile_action.cfm --->

<cffile action="uploadall" destination="#expandPath('./myuploads')#" nameconflict="overwrite" />
0
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 334 total points
ID: 39208779
You need "fiefield" attribute with <cffile> tag.

This specified the name of form field used to select the file
e.g

<!--- EXAMPLE --->

<!--- Check to see if the Form variable exists. --->
<cfif isDefined("Form.FileContents") >
    <!--- If TRUE, upload the file. --->
    <cffile action = "upload"
        fileField = "FileContents"
        destination = "c:\files\upload\"
        accept = "text/html"
        nameConflict = "MakeUnique">
<cfelse>
    <!--- If FALSE, show the Form. --->
    <form method="post" action=<cfoutput>#cgi.script_name#</cfoutput>
        name="uploadForm" enctype="multipart/form-data">
        <!---- FILE IS SELECTED BY THIS FIELD --->

        <input name="FileContents" type="file">
        <br>
        <input name="submit" type="submit" value="Upload File">
    </form>
</cfif>
0
 
LVL 4

Author Comment

by:koila
ID: 39208959
how i'm able to fixed into my code?
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 39210743
Can you upload your form code and code you would like me fix.

Thanks
0
 
LVL 4

Author Comment

by:koila
ID: 39238510
it didn't work yet. I 'm still figuring out so I put it a side for today I will take a look tomorrow on this code. I will have another question today.
0
 
LVL 4

Author Comment

by:koila
ID: 39297260
Hello,

it didn't work :( :( I will upload the file. Could you please help me.
0
 
LVL 4

Author Comment

by:koila
ID: 39297410
The error is happens on line 64.


 <cffile action="upload"
     fileField="fileUpload"
     destination="#application.directory_path#\members\toolkit\import\#parsed_file_name#">
     <p>Thankyou, your file has been uploaded.</p>

What is causing this error.

Thank you very much for your help and advise.
update-.txt
import-file.jpg
i-am-to-browse.jpg
error.jpg
0
 
LVL 4

Author Closing Comment

by:koila
ID: 39351857
thank you.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question