troubleshooting Question

File upload

Avatar of lulu50
lulu50Flag for United States of America asked on
ColdFusion Language
4 Comments2 Solutions513 ViewsLast Modified:
Hi,

I am using on my application a file upload to let the user upload images or any type of files.

My question is with the code I posted below, can I upload an email file?

Please, tell me why I can upload any other type of file but not an email file?

Can coldfusion, upload an email file?

Thanks,
Lulu

<cfsetting showdebugoutput="yes">
 <cfset filelocation = expandpath('uploadedfiles/')> 
<cfset maxFiles = 3>
<cfset x=0>
<cfset cnt=0>
<cfset Attachments="">
      <cfloop from="1" to="#variables.maxFiles#" index="ii">
     
      <cftry>
            <cfif StructKeyExists(form,"AttachFile" & ii) && len(trim(Form["AttachFile" & ii]))>
             <CFFILE ACTION="UPLOAD"
                        FILEFIELD="AttachFile#ii#"
                        DESTINATION="#variables.filelocation#"
                        NAMECONFLICT="makeunique">
     
             <cfset Attachments=ListAppend(variables.Attachments,cffile.serverfile)>  
            
            </cfif>

			<cfif StructKeyExists(form,"FileID" & ii) && len(trim(Form["FileID" & ii]))>
           <cfset variables["FileID" & ii] = Form["FileID" & ii]>
           </cfif>
           
           <cfif StructKeyExists(form,"FileDescription" & ii) && len(trim(Form["FileDescription" & ii]))>
           <cfset variables["Descp" & ii] = Form["FileDescription" & ii]>
		   </cfif>
            
            <cfcatch>
            <br>#cfcatch.message#<br>#cfcatch.detail#<br>
            #cfcatch.tagContext[1].template# Line #cfcatch.tagContext[1].line#
            </cfcatch></cftry>
            
      </cfloop>

 <cfloop from="1" to="#variables.maxFiles#" index="ii">
<cfif (StructKeyExists(form,"FileID" & ii) && len(trim(Form["FileID" & ii]))) && #Form["FileID" & ii]# neq "">
<cfset x++/>

 	<cfquery name = "QGetFileName"  datasource="#strDSN#" username="#strUID#" password="#strPWD#">
 		select UploadedFile from Files
 		where FileID = #variables["FileID" & ii]#  
 	</cfquery>
	<cfset convertfile =  #tostring(tobinary(QGetFileName.UploadedFile))#>
	<cfset GetfileName = #ListLast(convertfile,"\")#>


   <cfquery name = "QUpdateFiles"  datasource="#strDSN#" username="#strUID#" password="#strPWD#">

 				update Files 
	               SET 
                   Description = 
                    <cfif (StructKeyExists(form,"FileDescription" & x) && len(trim(Form["FileDescription" & x])) && #variables["Descp" & x]# neq '')> 
                   			<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#variables["Descp" & x]#">, 
                      <cfelseif isDefined("QGetFileName") and QGetFileName.RecordCount gt 0>
                           '#GetfileName#', 
                        <cfelse>
                    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#ii#">, 
                        </cfif>
                        
                         <cfif StructKeyExists(form,"AttachFile" & x) && len(trim(Form["AttachFile" & x]))>
                         UploadedFile =  <cfqueryparam cfsqltype="cf_sql_longvarchar"
                                value="#ToBase64(variables.filelocation & cffile.serverfile)#">,
                                
                        uploadedasbinary =  <cfqueryparam cfsqltype="cf_sql_blob"
                                value="#FileReadBinary(variables.filelocation & cffile.serverfile)#">,
                         </cfif>
                        
                   CreatedDate = <cfqueryparam cfsqltype="cf_sql_date" value="#Now()#" />   
                    where FileID = #variables["FileID" & ii]# 

</cfquery>
<cfelseif (StructKeyExists(form,"AttachFile" & ii) && len(trim(Form["AttachFile" & ii]))) && #Form["AttachFile" & ii]# neq "">



   <cfloop list="#variables.Attachments#" index="ii">
   <cfset x++/>

  <cfquery name = "QInsertFiles"  datasource="#strDSN#" username="#strUID#" password="#strPWD#">
	Set Nocount On;

        <cfif (StructKeyExists(form,"AttachFile" & x) && len(trim(Form["AttachFile" & x]))) >

                  INSERT INTO Files
                        (FileName,Description,UploadedFile,IssueID,Status,CreatedDate,uploadedasbinary)
                  VALUES
                        ( 
                         <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#x#">,
  
                      <cfif (StructKeyExists(form,"FileDescription" & x) && len(trim(Form["FileDescription" & x])) && #variables["Descp" & x]# neq '')> 
                        <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#variables["Descp" & x]#">, 
                        <cfelse>
                        <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#ii#">, 
                        </cfif>
                        <cfqueryparam cfsqltype="cf_sql_longvarchar"
                                value="#ToBase64(variables.filelocation & ii)#">,
                    #IssID#, 
                    1, 
                    <cfqueryparam cfsqltype="cf_sql_date" value="#Now()#" /> ,
                    <cfqueryparam cfsqltype="cf_sql_blob"
                                value="#FileReadBinary(variables.filelocation & ii)#"> )     

          </cfif>
  </cfquery>
 </cfloop>   
</cfif>
</cfloop> 
ASKER CERTIFIED SOLUTION
gdemaria

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros