We help IT Professionals succeed at work.

File upload

lulu50
lulu50 asked
on
509 Views
Last Modified: 2014-05-06
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

Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
lulu50Web application

Author

Commented:
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
lulu50Web application

Author

Commented:
Thank you

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.