Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Update my file

Hi,

I am not sure what I'm doing wrong to prevent it from updating my files.

I just want to update my files.  

I am doing something wrong but not sure what it is.

Thanks,
Lulu


<!--- begin update Uploaded files --->
<cfsetting showdebugoutput="yes">
 <cfset filelocation = expandpath('uploadedfiles/')> 
<cfset maxFiles = 3>
<cfset Attachments="">
      <cfloop from="1" to="#variables.maxFiles#" index="ii">
      <cftry>
             <cfset variables["Descp" & ii] = Form["FileDescription" & ii]>
             <cfset variables["FileName" & ii] = Form["FileName" & ii]>
			 <cfset variables["FileID" & ii] = Form["FileID" & ii]>

            <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>
            <cfcatch>
            <br>#cfcatch.message#<br>#cfcatch.detail#<br>
            #cfcatch.tagContext[1].template# Line #cfcatch.tagContext[1].line#
            </cfcatch></cftry>
      </cfloop>


      <cfquery name = "QLogFiles"  datasource="#strDSN#" username="#strUID#" password="#strPWD#" result="rs">
			Set Nocount On;
				<cfset cnt=0>
                   <cfloop list="#variables.Attachments#" index="ii">
            <cfset cnt++/>	

               update Files 
               SET 

				<cfif #variables["Descp" & cnt]# neq ''>
					FileName = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#variables["Descp" & cnt]#">,
				<cfelse>
					FileName =  <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#variables["FileName" & cnt]#">,
				</cfif>
          
            <cfif len(trim(variables.Attachments))> 
          <cfif FileExists(variables.filelocation & ii)>
      			<cfif IsDefined('ToBase64(variables.filelocation & ii)') && #ToBase64(variables.filelocation & ii)# neq ''>
					UploadedFile = <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#ToBase64(variables.filelocation & ii)#">,
				</cfif>
                     
            	<cfif IsDefined('ToBase64(variables.filelocation & ii)') && #ToBase64(variables.filelocation & ii)# neq ''>
					uploadedasbinary = <cfqueryparam cfsqltype="cf_sql_blob" value="#FileReadBinary(variables.filelocation & ii)#">,
				</cfif>
         </cfif>
         </cfif>
   					CreatedDate = <cfqueryparam cfsqltype="cf_sql_date" value="#Now()#">

       		WHERE FileID = #variables["FileID" & ii]#  
      </cfloop>
</cfquery>


<cfoutput>SQL: #rs.SQL#</cfoutput> 

<!--- end of update file --->

Open in new window

Avatar of Coast Line
Coast Line
Flag of Canada image

Hi Lulu, I would like to see you exact code and what you need here is this like this:

1. Show the image or doc file on the screen.
2. upload another file and replace one.
3. delete existing files..

can you show your complete code here
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
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
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 lulu50

ASKER

Thank you.

I got it to work!!!!!!