Avatar of lulu50
lulu50
Flag for United States of America asked on

File upload

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> 

Open in new window

ColdFusion Language

Avatar of undefined
Last Comment
lulu50

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
gdemaria

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Coast Line

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
lulu50

ASKER
gdemaria and myselfrandhawa Thank you for your response to my question.

gdemaria - I need your help please.  ( I have an open question that you are the only one that can help me with, because we worked on it together. So, you know what I'm looking for.)

 Here is a link to the question:
https://www.experts-exchange.com/Programming/Languages/Scripting/Cold_Fusion_Markup_Language/Q_28422355.html
lulu50

ASKER
Thank you
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes