Link to home
Start Free TrialLog in
Avatar of koila
koilaFlag for Australia

asked on

how do you upload a file in coldfusion.

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
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

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

https://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/A_2888-Uploading-a-File-in-Coldfusion.html
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
@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?
Avatar of koila

ASKER

yes, I've switch the hosts too. I will found out from the provider.
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#">
SOLUTION
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of koila

ASKER

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">
Avatar of koila

ASKER

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#">
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of koila

ASKER

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 --->
Avatar of koila

ASKER

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

Avatar of koila

ASKER

AGX, what do you think how i'm able to fix this issue.
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" />
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of koila

ASKER

how i'm able to fixed into my code?
Can you upload your form code and code you would like me fix.

Thanks
Avatar of koila

ASKER

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.
Avatar of koila

ASKER

Hello,

it didn't work :( :( I will upload the file. Could you please help me.
Avatar of koila

ASKER

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
Avatar of koila

ASKER

thank you.