Solved

Best practice for renaming an uploaded file when using CFFILE

Posted on 2013-06-17
7
357 Views
Last Modified: 2013-06-18
I am trying to fix some quirks in our CMS...when I upload a picture, it uses, CFFILE and then it passes the variable on to be added to the database. There are usually multiple sections to each page, so each 'section' is looped, id'd and processed. It looks like this, when it comes to the code that actually uploads the file and puts it on the server


<cffile action="UPLOAD"
       filefield="new_pic#text_seq#"
       destination="#s_ptag_serverpath1#"
       nameconflict="OVERWRITE">
      <cfset "picture#text_seq#" = "#file.serverfile#">

1) ) The "new_pic#text_seq#" renders as new_pic4 (for example, the new pic for the fourth section).
2) the #s_ptag_serverpath1# is the directory that the file goes in.
3) The "picture#text_seq# (renders as "picture4" for the fourth section) is a variable that is then set to the file name, the variable is then sent on to be processed in the application, where the name is added to the database, for that graphic field.

The problem is that when a customer uploads a file the first time, everything works fine. If the customer uses the same graphic in a second section, the overwrite function prevents an error. The problem comes when the user/customer deletes the first or the second instance, which wipes it from the respective database field and then the file from the server - leaving the other instance still there in the database, but not on the server.

I need the second instance to be unique; I need to change the name of the file, after it is uploaded, but also need to set the value of the variable that passes the name on as well.

A file list is built of all the files in the directory, that the name can be checked against - so as to invoke the conditional statement of a rename function, I just don't know how to code it, or what the best way to do it is.

What is the best way to do this?

I
0
Comment
Question by:btintermedia
  • 4
  • 3
7 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39254032
I don't know how much latitude you have with the CMS, but ... is there a reason you can't just use unique file names instead?  

I rarely use "overwrite" for uploads because it can create other problems.  Just because the file names are the same, is no guarantee they are - or should be treated as - the same..  For example, using overwrite, my code could accidentally replace someone's corporate logo with a picture of a cat .. simply because they have the same name.  I prefer to make all file names unique. Then let the user decided which images remove/replace through the app interface.
0
 

Author Comment

by:btintermedia
ID: 39255274
Dear _agx_,

I agree. I do not want to use the 'overwrite' function anymore - but neither do I want to throw a cold fusion error. In the submit process, multiple graphics could be submitted, depending on how the user has changed content in the various 'section' that are all updated upon submission of the form.

I think that I know how to compare the file name against a list of previously uploaded files - but I do not know how to variable name on the fly. I suppose I could append an '_1' to the file name - but I am not sure how to do that in a way so that *both* the file that is uploaded is changed to the new name, as well as the variable that is passed to the database for the purpose of keeping track of it.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39256233
In the submit process, multiple graphics could be submitted, depending on how the user has changed content in the various 'section' that are all updated upon submission of the form.
I think that I know how to compare the file name against a list of previously uploaded files

I think I understand the goal, but it's hard to say what changes are needed in the submission process - without seeing the screen/code.  This may be a silly question, but I'm not following why you need to do a comparison at all... Wouldn't it be simpler to just DELETE the old records/files when the form is submitted, and INSERT the new information?

- but I do not know how to variable name on the fly. ....

BTW: You can read/write variables dynamically using array notation ie  VARIABLES["new_pic"& counter]
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:btintermedia
ID: 39257717
q_text.cfml

This is the page that the form submits to. It is important to understand that this page sits on a 'child site' and the bulk of the backend processessing takes place on the 'parent site' - but all the graphics processing takes place on the child site, so that is all you will see here.



There are loops, which account for each section, and there there are loops which account for each section that is processed and cfhttp'd to the parent site, where all the database content is updated. The user defined graphics are the only content that is left on the child site- all the site content (and site design) is parsed cfhttp's back to the child site.

the other page is the include where the actual file processing takes place

In regards to your question, it is not dumb - but it is important to realize the problem. A user could upload the same graphic in multiple sections and this would cause problems, if it is deleted or updated in the first or second instance. I am trying to keep it simple, so if a second instance of the same graphic is uploaded, I want to make the file name (and the associated variable name, that is passed off to the parent site, where it is kept track of) unique as well.


---------------------------------------------------------------------------------------------------------------------------
BEGIN   -     Q_text.cfml
---------------------------------------------------------------------------------------------------------------------------


<cfif msc_app_ver neq "3.0" and msc_app_ver lt "3.0">



</cfif>
<!--- ABOVE IS PRE 3.0 CODE --->










































<cfif msc_app_ver is "3.0" or msc_app_ver gt "3.0">



<cfinclude template="master_config.cfm">
<!-- BEGIN  STATIC PERSONALIZATION TAGS -->
<!--- Static Personaoity tags version 1.0  ---->
<!-- these tags are designed to improve the functionalitiy, security and ease of setup of these pages.
They are static for each page and personalize this code for use withing the given website.
During an upgrade all that is invloved is replacing this page with the updated page and making sure that these valuse are plugged into their corresponding tags so you don't have to go hunting through the code

Instructions for ptag_serverpath:
this tag is referenced in the code below and is the server path for image uploads, change it here 
Instructions for s_ptag_church_id:
this tag is referenced in the code below and is the church id for the site that uses this page 
--->

<!--- Static Personality Tags v.2.0 ! Yo - it is no longer handled here but on the <cfinclude template="master_config.cfm"> page, so the s_ptag_serverpath1 and s_ptag_church_id now reference back to it, If you are redoing this page - then this reduntant hand off can be taken out at some point in time to reduce server load/app efficiency, but then if I did not write so much then that would too right? 
--->


	<cfset s_ptag_serverpath1 = "#sec_ssv_site_root#">
	<cfset s_ptag_church_id = "#sec_ssv_church_id#">
    
<!---
<cfoutput>

s_ptag_serverpath1 is "#s_ptag_serverpath1#"<br />
</cfoutput>

--->

<!-- End static personalization tags --->

<!-- BEGIN DYNAMIC PERSONALIZXATION TAGS -->
<!--- these taga are not in use yet, they are personality traits that are dynamicallly assigned based on user state, and will influence access and appearance.

example will be d_ptag_user_security_groups

--->

<!--- END DUNAM<IC PERSONALIZATION TAGS  --->

<cfoutput>

<cfparam name="article_type" default="P">


<!--- this section is now offline, since all S, A, M, H, P have all the same code for text sections

<cfif article_type is "A" or article_type is "M" or article_type is "S">

<!--- Begin variables that are used when this page is used for S, A, M --->
<cfparam name="file1" default="">
<cfparam name="file2" default="">
<cfparam name="file3" default="">
<CFPARAM NAME="Shared" DEFAULT="">
<CFPARAM NAME="no_show_bio" DEFAULT="">
<CFPARAM NAME="CALENDAR_LOC" DEFAULT="">
<CFPARAM NAME="CALENDAR_DESC" DEFAULT="">
<CFPARAM NAME="REMOVE" DEFAULT="">		
<CFPARAM NAME="HEADING_NEW" DEFAULT="">
<CFPARAM NAME="SECTION_CONTENT_NEW" DEFAULT="">
<CFPARAM NAME="USEPIC" DEFAULT="">
<CFPARAM NAME="ANOTHER" DEFAULT="">
<CFPARAM NAME="NEWPIC" DEFAULT="">
<CFPARAM NAME="PICHEIGHT" DEFAULT="">
<CFPARAM NAME="PICWIDTH" DEFAULT="">
<CFPARAM NAME="PICBORDER" DEFAULT="">
<CFPARAM NAME="PICSPACE" DEFAULT="">
<CFPARAM NAME="PICJUSTIFY" DEFAULT="">
<CFPARAM NAME="article_date" DEFAULT="">
<!--- end variables that are used when this page is used for S, A, M --->








<!--- BEGIN A,S & M GRAPHICS Processing! ---->
 

<!-- FIRST HANDLE THE FILES -->		
<!-- ANYTHING BUT 'AS IS' INDICATES A CHANGE TO THE FILE. SO FIRST DELETE THE OLD ONE. -->
<cfif (file_option1 is not "asis")>
	<cfif orig_file1 is not "">	
		<cffile action="DELETE" file="#s_ptag_serverpath1##orig_file1#">	</cfif>
		<cfif ((file_option1 is "upload") or (file_option1 is "newupload")) and (file_content1 is not "")>
		<cffile action="UPLOAD" filefield="file_content1" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset file1 = "#file.serverfile#">
		</cfif>
	
	<cfif ((file_option1 is "upload") or (file_option1 is "newupload")) and (file_content1 is not "")>
		<cffile action="UPLOAD" filefield="file_content1" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset file1 = "#file.serverfile#">
		</cfif>
		
<cfelse>
	<cfset file1 = "#orig_file1#">
</cfif>

<cfif (file_option2 is not "asis")>
	<cfif orig_file2 is not "">	<cffile action="DELETE" file="#s_ptag_serverpath1##orig_file2#">	</cfif>
		<cfif ((file_option2 is "upload") or (file_option2 is "newupload")) and (file_content2 is not "")>
		<cffile action="UPLOAD" filefield="file_content2" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset file2 = "#file.serverfile#">
		</cfif>
	<cfif ((file_option2 is "upload") or (file_option2 is "newupload")) and (file_content2 is not "")>
		<cffile action="UPLOAD" filefield="file_content2" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset file2 = "#file.serverfile#">
		</cfif>
	
<cfelse>
	<cfset file2 = "#orig_file2#">
</cfif>

<cfif (file_option3 is not "asis")>
	<cfif orig_file3 is not "">	<cffile action="DELETE" file="#s_ptag_serverpath1##orig_file3#">	</cfif>
		<cfif ((file_option3 is "upload") or (file_option3 is "newupload")) and (file_content3 is not "")>
		<cffile action="UPLOAD" filefield="file_content3" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset file3 = "#file.serverfile#">
		</cfif>
	<cfif ((file_option3 is "upload") or (file_option3 is "newupload")) and (file_content3 is not "")>
		<cffile action="UPLOAD" filefield="file_content3" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset file3 = "#file.serverfile#">
		</cfif>
			
<cfelse>
	<cfset file3 = "#orig_file3#">
</cfif>




<!--- END A,S & M GRAPHICS Processing! ---->


</cfif>


--->














<!---Begin Graphics Processing for reset of page --->
<!-- FIRST BEGIN BY HANDLING THE GRAPHIC UPLOADS (BOTTOM) -->


<!--- previous code 
<cfloop from="1" to="#norecs#" index="thisrow">
	
	<cfset text_seq = "#evaluate("ts" & thisrow)#">
    <CFSET "alt_type#text_seq#" = "#evaluate("alt_type" & text_seq)#">
    <cfif ("alt_type#text_seq#" eq "") or ("alt_type#text_seq#" eq 'text1')>
    including code for text_inc<br />
   <!--- <cfinclude template="q_text_inc_text1.cfm"> --->
    <cfelseif "alt_type#text_seq#" eq 'spacer'>
    this is a spacer
    <cfelse>
    we are undefined and therefore proceeding to debug mode<br />
    my alt_type#text_seq# = "#evaluate("alt_type" & text_seq)#"<br /><br />
    </cfif>
    
    
    
</cfloop>
--->




<cfloop from="1" to="#norecs#" index="thisrow">
      
    <cfset text_seq = "#evaluate("ts" & thisrow)#">
    <cfset Variables['alt_type#text_seq#'] = "#evaluate("alt_type" & text_seq)#" />
    
	<cfif (Variables['alt_type#text_seq#'] eq "") or (Variables['alt_type#text_seq#'] eq 'text1')>
    <!---	including code for text_inc<br /> --->
   		 <cfinclude template="q_text_inc_text1.cfm"> 
    <cfelseif Variables['alt_type#text_seq#'] eq 'spacer'>
    <!---	this is a spacer<br /> --->
    <cfelse>
    	we are undefined and therefore proceeding to debug mode<br />
    	my alt_type#text_seq# = "#evaluate("alt_type" & text_seq)#"<br /><br />
    </cfif>
   
   
   
</cfloop>



</cfoutput>




<!--- we have now finished the file processing tasks that were accomplished on the parent site, now we move on the database updates, which are accomplished on the k@h site  --->





<!--- begin standard H & P Params --->
<cfparam name="delete" default="no">
<cfparam name="delpage" default="no">
<cfparam name="bottomnav" default="">
<cfparam name="topnav" default="">
<cfparam name="sort_condition" default="">
<cfparam name="security_realm_condition" default="">
<cfparam name="security_group" default="">

<cfparam name="usepic" default="">
<!--- new params 07/27/10 --->
<cfparam name="page_entity_variable" default="">
<cfparam name="page_nature" default="">
<cfparam name="modality_archetype" default="">
<!--- this is passed by a text section if it is present
so that the update page knows to execute the update 
query - otherwise, if it is absent, it will throw an error --->
<cfparam name="meaningful_content" default="">

<!--- end standard H & P Params --->
<!--- begin S,M, A Params --->
<cfparam name="article_type" default="">
<cfparam name="no_show_bio" default="">
<cfparam name="Shared" default="">

<!--- end S,M, A Params --->

<CFHTTP METHOD="POST" URL="http://www.KingdomAtHand.com/modules/q_hometext.cfm">
	<CFHTTPPARAM NAME="MSC_APP_VER" TYPE="URL" VALUE="#MSC_APP_VER#">
    <CFHTTPPARAM NAME="norecs" TYPE="URL" VALUE="#norecs#">
	<CFHTTPPARAM NAME="church_id" TYPE="URL" VALUE="#church_id#">
	<CFHTTPPARAM NAME="page_name" TYPE="URL" VALUE="#page_name#">
	<CFHTTPPARAM NAME="delete" TYPE="URL" VALUE="#delete#">
	<CFHTTPPARAM NAME="delpage" TYPE="URL" VALUE="#delpage#">
	<CFHTTPPARAM NAME="topnav" TYPE="URL" VALUE="#topnav#">
	<CFHTTPPARAM NAME="bottomnav" TYPE="URL" VALUE="#bottomnav#">
	<CFHTTPPARAM NAME="sort_condition" TYPE="URL" VALUE="#sort_condition#">
	<CFHTTPPARAM NAME="security_realm_condition" TYPE="FormField" VALUE="#security_realm_condition#">
	<CFHTTPPARAM NAME="security_group" TYPE="FormField" VALUE="#security_group#">
    <CFHTTPPARAM NAME="page_entity_variable" TYPE="URL" VALUE="#page_entity_variable#">
    <CFHTTPPARAM NAME="page_nature" TYPE="URL" VALUE="#page_nature#">
    <CFHTTPPARAM NAME="modality_archetype" TYPE="URL" VALUE="#modality_archetype#">
    <CFHTTPPARAM NAME="meaningful_content" TYPE="URL" VALUE="#meaningful_content#">
    <CFHTTPPARAM NAME="article_type" TYPE="URL" VALUE="#article_type#">
    <CFHTTPPARAM NAME="node_id" TYPE="URL" VALUE="#node_id#">
    
    
    
    <!--- new params 07/27/10 --->
    
	<!--- begin S,M, A CFHTTParams --->
    
   
    
	
	<cfif article_type is "A" or article_type is "M" or article_type is "S">	
	
			<CFHTTPPARAM NAME="article_id" TYPE="URL" VALUE="#page_entity_variable#">		
			<CFHTTPPARAM NAME="article_date" TYPE="URL" VALUE="#article_date#">	
			<CFHTTPPARAM NAME="author_name" TYPE="URL" VALUE="#author_name#">	
			<CFHTTPPARAM NAME="article_title" TYPE="URL" VALUE="#article_title#">	
			<CFHTTPPARAM NAME="article_subtitle" TYPE="URL" VALUE="#article_subtitle#">
			<CFHTTPPARAM NAME="Shared" TYPE="FormField" VALUE="#Shared#">
			<CFHTTPPARAM NAME="no_show_bio" TYPE="FormField" VALUE="#no_show_bio#">
            
            
			<!---
            <CFHTTPPARAM NAME="file1" TYPE="URL" VALUE="#file1#">	
			<CFHTTPPARAM NAME="file2" TYPE="URL" VALUE="#file2#">	
			<CFHTTPPARAM NAME="file3" TYPE="URL" VALUE="#file3#">	
			<CFHTTPPARAM NAME="remove" TYPE="URL" VALUE="#remove#">
			--->
			<CFHTTPPARAM NAME="msc_app_ver" TYPE="URL" VALUE="3.0">	       	
	</cfif>
	
	
	
	
	
	<!--- end S,M, A CFHTTPParams --->
	<cfoutput>
    
    
		<cfloop from="1" to="#norecs#" index="thisrow">
		<cfset text_seq = "#evaluate("ts" & thisrow)#">
		<cfparam name="delete#text_seq#" default="no">
     <!--- all variables that are universal, or are common regardless of type of section --->   
     <CFHTTPPARAM NAME="delete#text_seq#" TYPE="FormField" VALUE="#evaluate("delete" & text_seq)#">
     <CFHTTPPARAM NAME="sort_order#text_seq#" TYPE="FormField" VALUE="#evaluate("sort_order" & text_seq)#">
      <CFHTTPPARAM NAME="alt_type#text_seq#" TYPE="FormField" VALUE="#evaluate("alt_type" & text_seq)#">  
    		<cfset text_seq = "#evaluate("ts" & thisrow)#">
   			<cfset Variables['alt_type#text_seq#'] = "#evaluate("alt_type" & text_seq)#" />
    		<cfif (Variables['alt_type#text_seq#'] eq "") or (Variables['alt_type#text_seq#'] eq 'text1')>
        
        
		<!--- variables that are unique to text1 --->
		<CFHTTPPARAM NAME="heading#text_seq#" TYPE="FormField" VALUE="#evaluate("heading" & text_seq)#">
		<CFHTTPPARAM NAME="var_file_content1#text_seq#" TYPE="FormField" VALUE="#evaluate("var_file_content1" & text_seq)#">
		<CFHTTPPARAM NAME="var_file_content2#text_seq#" TYPE="FormField" VALUE="#evaluate("var_file_content2" & text_seq)#">
		<CFHTTPPARAM NAME="var_file_content3#text_seq#" TYPE="FormField" VALUE="#evaluate("var_file_content3" & text_seq)#">
		<CFHTTPPARAM NAME="verbiage#text_seq#" TYPE="FormField" VALUE="#evaluate("verbiage" & text_seq)#">
		<CFHTTPPARAM NAME="spanclass#text_seq#" TYPE="FormField" VALUE="#evaluate("spanclass" & text_seq)#">
		<CFHTTPPARAM NAME="picture#text_seq#" TYPE="FormField" VALUE="#evaluate("picture" & text_seq)#">
		<CFHTTPPARAM NAME="picjustify#text_seq#" TYPE="FormField" VALUE="#evaluate("picjustify" & text_seq)#">
		<CFHTTPPARAM NAME="picwidth#text_seq#" TYPE="FormField" VALUE="#evaluate("picwidth" & text_seq)#">
		<CFHTTPPARAM NAME="picheight#text_seq#" TYPE="FormField" VALUE="#evaluate("picheight" & text_seq)#">
		<CFHTTPPARAM NAME="picborder#text_seq#" TYPE="FormField" VALUE="#evaluate("picborder" & text_seq)#">
		<CFHTTPPARAM NAME="picspace#text_seq#" TYPE="FormField" VALUE="#evaluate("picspace" & text_seq)#">
        <CFHTTPPARAM NAME="usepic#text_seq#" TYPE="FormField" VALUE="#evaluate("sort_order" & text_seq)#">
        
        <cfelseif Variables['alt_type#text_seq#'] eq 'spacer'>
        <!---variables that are unique to spacer --->
          <CFHTTPPARAM NAME="spacer_value#text_seq#" TYPE="FormField" VALUE="#evaluate("spacer_value" & text_seq)#">
        
        
       <cfelse>
       </cfif>
        
        <!---my alt_type#text_seq# = "#evaluate("alt_type" & text_seq)#" --->
		</cfloop>
	</cfoutput>
</CFHTTP>

<!--- this variable may not be stated in earlier versions, so we state it here --->
<cfparam name="E_HomeText_as_cal_inc" default="">
	
<cfif E_HomeText_as_cal_inc contains "yes">
<!--- we do not need the headers for this page, as it is being used as an include, in the calender update process and in being called from the cleint side by the calender --->
<cfelse>
<cfinclude template="pagestart.cfm">

</cfif>

<table border="0" cellspacing="0" cellpadding="15" width="100%"> 
  <tr> 
     <td class="caption" valign="top" bgcolor="#FFFFFF">
	 

	 
	 <CFOUTPUT>		#cfhttp.filecontent#		</cfoutput>
     

  

          
  	</td> 
   </tr> 
</table> 


<cfif E_HomeText_as_cal_inc contains "yes">
<!--- we do not need the headers for this page, as it is being used as an include, in the calender update process and in being called from the cleint side by the calender --->
<cfelse>

<cfinclude template="pageend.cfm">
</cfif>





</cfif>

Open in new window





---------------------------------------------------------------------------------------------------------------------------
END   -     Q_text.cfml
---------------------------------------------------------------------------------------------------------------------------








---------------------------------------------------------------------------------------------------------------------------
BEGIN   -    Q_text_inc_text1.cfml  (include for Q_text.cfm)
---------------------------------------------------------------------------------------------------------------------------

<!--set the text-seq variable -->
	<cfset text_seq = "#evaluate("ts" & thisrow)#">
	
	<!-- set the operators for the picture -->
	<cfparam name="orig_pic#text_seq#" default="">
	<cfset op = "#evaluate("orig_pic" & text_seq)#">
	
	<!-- pass any existing file names as variable operators -->
	<cfparam name="orig_file_content1#text_seq#" default="">
	<cfset of1 = "#evaluate("orig_file_content1" & text_seq)#">
	<!-- set the operators for the second file -->
	<cfparam name="orig_file_content2#text_seq#" default="">
	<cfset of2 = "#evaluate("orig_file_content2" & text_seq)#">
	<!-- set the operators for the third file -->
	<cfparam name="orig_file_content3#text_seq#" default="">
	<cfset of3 = "#evaluate("orig_file_content3" & text_seq)#">
	
	
	<!-- pass new file names as variable operators -->
	<cfparam name="new_file_content1#text_seq#" default="">
	<cfset nf1 = "#evaluate("new_file_content1" & text_seq)#">
	<!-- set the operators for the second file -->
	<cfparam name="new_file_content2#text_seq#" default="">
	<cfset nf2 = "#evaluate("new_file_content2" & text_seq)#">
	<!-- set the operators for the third file -->
	<cfparam name="new_file_content3#text_seq#" default="">
	<cfset nf3 = "#evaluate("new_file_content3" & text_seq)#">
	
	
	
	
	
	<cfparam name="var_file_content1#text_seq#" default="">
	<cfparam name="var_file_content2#text_seq#" default="">
	<cfparam name="var_file_content3#text_seq#" default="">
    <cfparam name="usepic#text_seq#" default="">
    <cfparam name="picture#text_seq#" default="">
    <cfparam name="newpic#text_seq#" default="">
		
<!-- BEGIN WORK ON FILES -->


<!-- BBEGIN WORK ON ATTATCGHEMENT FILE NUMBER ONE -->



<!-- If the file option for the first file is set to as is...-->
<!-- BEGIN ASIS LOGIC->
	<cfif (evaluate("file_option1" & text_seq) is "asis")>
		<!-- then we set the variable to be passed to the database to the existing name stored in of1, from above -->
		<cfset "var_file_content1#text_seq#" = "#of1#">







<!-- END ASIS LOGIC->


<!--BEGIN ANOTHER_UPLOAD -->		
<!-- if the settng is not set to current it is set to use another_upload and existing is not blank -->	
	<cfelseif (evaluate("file_option1" & text_seq) is "another_upload") and (evaluate("orig_file_content1" & text_seq) is not "")>
			<!-- Begin sub-condiiton --> 
			<!-- and if the of1 is not blank then before we do anything else, we delete it -->
			<cfif of1 is not "">
				<cffile action="DELETE" file="#s_ptag_serverpath1##of1#" nameconflict="skip"> 
			</cfif>
			<!-- end sub-condiiton --> 
		<!-- remember, we are stil working with 'another_upload' so with the old replaced, we now set the replacement -->
		
		
	
		
		<!-- then we upload the file for "another_upload" -->
		<cffile action="UPLOAD" filefield="new_file_content1#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE"><cfset "var_file_content1#text_seq#" = "#file.serverfile#">
		

<!-- END ANOTHER_UPLOAD LOGIC->



<!--BEGIN NEW LOGIC->	
	<!-- but what if the option is set to new?  and if it IS NOT blank?-->
	<!-- BEGIN NEW BUT NOT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option1" & text_seq) is "new_upload") and (evaluate("orig_file_content1" & text_seq) is not "")>
	
	
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of1#">	
		<!-- then we upload the new for new -->
		<cffile action="UPLOAD" filefield="new_file_content1#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<!-- and then designate it to be passed on to the database -->
		<cfset "var_file_content1#text_seq#" = "#file.serverfile#">
	<!-- END NEW BUT NOT BLANK LOGIC -->
	
	<!-- but what if the option is set to new?  and if it IS blank?-->
	<!-- BEGIN NEW BUT AND BLANK LOGIC -->
	<cfelseif (evaluate("file_option1" & text_seq) is "new_upload") and (evaluate("orig_file_content1" & text_seq) is "")>
		<!-- then we upload the new for new -->
		<cffile action="UPLOAD" filefield="new_file_content1#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<!-- and then designate it to be passed on to the database -->
		<cfset "var_file_content1#text_seq#" = "#file.serverfile#">
		
	
		
	<!-- END NEW BUT AND BLANK LOGIC -->
<!--END NEW LOGIC->	




<!--BEGIN NONE LOGIC-->	
	<!-- BEGIN NONE BUT NOT BLANK LOGIC -->
	<cfelseif (evaluate("file_option1" & text_seq) is "none") and (evaluate("orig_file_content1" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of1#">
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content1#text_seq#" = "">
	<!-- END NONE BUT NOT BLANK LOGIC -->
		
	<!-- BEGIN NONE AND BLANK LOGIC -->
	<cfelseif (evaluate("file_option1" & text_seq) is "none") and (evaluate("orig_file_content1" & text_seq) is "")>
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content1#text_seq#" = "">

	
	<!-- END NONE AND BLANK LOGIC -->
<!--END NONE LOGIC-->
	
	
<!--BEND DELETE LOGIC->
	<!-- BEGIN DELETE BUT NOT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option1" & text_seq) is "delete") and (evaluate("orig_file_content1" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of1#">
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content1#text_seq#" = "">
	<!-- END DELETE BUT NOT BLANK LOGIC -->
	
	<!-- BEGIN DELETE BUT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option1" & text_seq) is "delete") and (evaluate("orig_file_content1" & text_seq) is "")>
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content1#text_seq#" = "">
</cfif>
	<!-- BEGIN DELETE BUT BLANK LOGIC -->
<!--END DELETE LOGIC->
<!-- END WORK ON ATTATCGHEMENT FILE NUMBER ONE -->	











<!-- BEGIN WORK ON ATTATCGHEMENT FILE NUMBER TWO -->
<!-- If the file option for the first file is set to as is...-->
<!-- BEGIN ASIS LOGIC->
	<cfif (evaluate("file_option2" & text_seq) is "asis")>
		<!-- then we set the variable to be passed to the database to the existing name stored in of1, from above -->
		<cfset "var_file_content2#text_seq#" = "#of2#">
<!-- END ASIS LOGIC->


<!--BEGIN ANOTHER_UPLOAD -->		
<!-- if the settng is not set to current it is set to use another_upload and existing is not blank -->	
	<cfelseif (evaluate("file_option2" & text_seq) is "another_upload") and (evaluate("orig_file_content2" & text_seq) is not "")>
			<!-- Begin sub-condiiton --> 
			<!-- and if the of1 is not blank then before we do anything else, we delete it -->
			<cfif of2 is not "">
				<cffile action="DELETE" file="#s_ptag_serverpath1##of2#">
			</cfif>
			<!-- end sub-condiiton --> 
		<!-- remember, we are stil working with 'another_upload' so with the old replaced, we now set the replacement -->
		
		<!-- then we upload the file for "another_upload" -->
		<cffile action="UPLOAD" filefield="new_file_content2#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE"><cfset "var_file_content2#text_seq#" = "#file.serverfile#">
<!-- END ANOTHER_UPLOAD LOGIC->



<!--BEGIN NEW LOGIC->	
	<!-- but what if the option is set to new?  and if it IS NOT blank?-->
	<!-- BEGIN NEW BUT NOT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option2" & text_seq) is "new_upload") and (evaluate("orig_file_content2" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of2#">	
		<!-- then we upload the new for new -->
		<cffile action="UPLOAD" filefield="new_file_content2#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<!-- and then designate it to be passed on to the database -->
		<cfset "var_file_content2#text_seq#" = "#file.serverfile#">
	<!-- END NEW BUT NOT BLANK LOGIC -->
	
	<!-- but what if the option is set to new?  and if it IS blank?-->
	<!-- BEGIN NEW BUT AND BLANK LOGIC -->
	<cfelseif (evaluate("file_option2" & text_seq) is "new_upload") and (evaluate("orig_file_content2" & text_seq) is "")>
		<!-- then we upload the new for new -->
		<cffile action="UPLOAD" filefield="new_file_content2#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<!-- and then designate it to be passed on to the database -->
		<cfset "var_file_content2#text_seq#" = "#file.serverfile#">
	<!-- END NEW BUT AND BLANK LOGIC -->
<!--END NEW LOGIC->	




<!--BEGIN NONE LOGIC-->	
	<!-- BEGIN NONE BUT NOT BLANK LOGIC -->
	<cfelseif (evaluate("file_option2" & text_seq) is "none") and (evaluate("orig_file_content2" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of2#">
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content2#text_seq#" = "">
	<!-- END NONE BUT NOT BLANK LOGIC -->
		
	<!-- BEGIN NONE AND BLANK LOGIC -->
	<cfelseif (evaluate("file_option2" & text_seq) is "none") and (evaluate("orig_file_content2" & text_seq) is "")>
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content2#text_seq#" = "">
	<!-- END NONE AND BLANK LOGIC -->
<!--END NONE LOGIC-->
	
	
<!--BEND DELETE LOGIC->
	<!-- BEGIN DELETE BUT NOT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option2" & text_seq) is "delete") and (evaluate("orig_file_content2" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of2#">
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content2#text_seq#" = "">
	<!-- END DELETE BUT NOT BLANK LOGIC -->
	
	<!-- BEGIN DELETE BUT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option2" & text_seq) is "delete") and (evaluate("orig_file_content2" & text_seq) is "")>
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content2#text_seq#" = "">
</cfif>
	<!-- BEGIN DELETE BUT BLANK LOGIC -->
<!--END DELETE LOGIC->
<!-- END WORK ON ATTATCGHEMENT FILE NUMBER TWO -->
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
<!-- BEGIN WORK ON ATTATCGHEMENT FILE NUMBER THREE -->
<!-- If the file option for the first file is set to as is...-->
<!-- BEGIN ASIS LOGIC->
	<cfif (evaluate("file_option3" & text_seq) is "asis")>
		<!-- then we set the variable to be passed to the database to the existing name stored in of1, from above -->
		<cfset "var_file_content3#text_seq#" = "#of3#">
<!-- END ASIS LOGIC->


<!--BEGIN ANOTHER_UPLOAD -->		
<!-- if the settng is not set to current it is set to use another_upload and existing is not blank -->	
	<cfelseif (evaluate("file_option3" & text_seq) is "another_upload") and (evaluate("orig_file_content3" & text_seq) is not "")>
			<!-- Begin sub-condiiton --> 
			<!-- and if the of1 is not blank then before we do anything else, we delete it -->
			<cfif of3 is not "">
				<cffile action="DELETE" file="#s_ptag_serverpath1##of3#">
			</cfif>
			<!-- end sub-condiiton --> 
		<!-- remember, we are stil working with 'another_upload' so with the old replaced, we now set the replacement -->
		
		<!-- then we upload the file for "another_upload" -->
		<cffile action="UPLOAD" filefield="new_file_content3#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE"><cfset "var_file_content3#text_seq#" = "#file.serverfile#">
<!-- END ANOTHER_UPLOAD LOGIC->



<!--BEGIN NEW LOGIC->	
	<!-- but what if the option is set to new?  and if it IS NOT blank?-->
	<!-- BEGIN NEW BUT NOT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option3" & text_seq) is "new_upload") and (evaluate("orig_file_content3" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of3#">	
		<!-- then we upload the new for new -->
		<cffile action="UPLOAD" filefield="new_file_content3#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<!-- and then designate it to be passed on to the database -->
		<cfset "var_file_content3#text_seq#" = "#file.serverfile#">
	<!-- END NEW BUT NOT BLANK LOGIC -->
	
	<!-- but what if the option is set to new?  and if it IS blank?-->
	<!-- BEGIN NEW BUT AND BLANK LOGIC -->
	<cfelseif (evaluate("file_option3" & text_seq) is "new_upload") and (evaluate("orig_file_content3" & text_seq) is "")>
		<!-- then we upload the new for new -->
		<cffile action="UPLOAD" filefield="new_file_content3#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<!-- and then designate it to be passed on to the database -->
		<cfset "var_file_content3#text_seq#" = "#file.serverfile#">
	<!-- END NEW BUT AND BLANK LOGIC -->
<!--END NEW LOGIC->	




<!--BEGIN NONE LOGIC-->	
	<!-- BEGIN NONE BUT NOT BLANK LOGIC -->
	<cfelseif (evaluate("file_option3" & text_seq) is "none") and (evaluate("orig_file_content3" & text_seq) is not "")>
		<!-- because the of3 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of3#">
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content3#text_seq#" = "">
	<!-- END NONE BUT NOT BLANK LOGIC -->
		
	<!-- BEGIN NONE AND BLANK LOGIC -->
	<cfelseif (evaluate("file_option3" & text_seq) is "none") and (evaluate("orig_file_content3" & text_seq) is "")>
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content3#text_seq#" = "">
	<!-- END NONE AND BLANK LOGIC -->
<!--END NONE LOGIC-->
	
	
<!--BEND DELETE LOGIC->
	<!-- BEGIN DELETE BUT NOT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option3" & text_seq) is "delete") and (evaluate("orig_file_content3" & text_seq) is not "")>
		<!-- because the of1 is not blank, we delete it -->
		<cffile action="DELETE" file="#s_ptag_serverpath1##of3#">
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content3#text_seq#" = "">
	<!-- END DELETE BUT NOT BLANK LOGIC -->
	
	<!-- BEGIN DELETE BUT BLANK LOGIC -->	
	<cfelseif (evaluate("file_option3" & text_seq) is "delete") and (evaluate("orig_file_content3" & text_seq) is "")>
		<!-- and then designate it to be passed on to the database as null -->
		<cfset "var_file_content3#text_seq#" = "">
</cfif>
	<!-- BEGIN DELETE BUT BLANK LOGIC -->
<!--END DELETE LOGIC->
<!-- END WORK ON ATTATCGHEMENT FILE NUMBER THREE -->	

<!-- END WORK ON FILES -->
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
<!-- WORK ON PICTURES -->
<!-- EGIN CURRENT LOGIC -->
<!-- if the picture is set to something, and we are supposed to leave it alone - we just pass it on -->
	<cfif (evaluate("usepic" & text_seq) is "current")>
		<cfset "picture#text_seq#" = "#op#">
<!-- EGIN CURRENT LOGIC -->

<!-- BEGIN ANOTHER LOGIC -->
<!-- if the settng is not set to current it is set to use another and is not blank -->	
	<cfelseif (evaluate("usepic" & text_seq) is "change") and (evaluate("orig_pic" & text_seq) is not "")>
<!-- we are under another setting and there appears to be an eixisting file -->
<!-- begin sub-condition logic -->
	<cfif op is not "">
		<cffile action="DELETE" file="#s_ptag_serverpath1##op#">
	</cfif>
<!-- end sub-condition logic -->
<!-- but we are still on 'another' and we need to handle it -->
<!-- we set the variable to equal it -->
	
<!-- then we upload it -->
<cffile action="UPLOAD" filefield="new_pic#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE"><cfset "picture#text_seq#" = "#file.serverfile#">
<!-- END ANOTHER LOGIC -->

<!-- BEGIN NEW LOGIC -->	
	<cfelseif (evaluate("usepic" & text_seq) is "new") and (evaluate("new_pic" & text_seq) is not "")>
		<!-- FIRST DELETE THE OLD PICTURE -->
		<!-- begin sub-condition logic -->
		<cfif op is not "">
		<cffile action="DELETE" file="#s_ptag_serverpath1##op#">
		</cfif>
		<!-- end sub-condition logic -->
		<!-- NEXT DESIGNATE THE NEW -->
		<cffile action="UPLOAD" filefield="new_pic#text_seq#" destination="#s_ptag_serverpath1#" nameconflict="OVERWRITE">
		<cfset "picture#text_seq#" = "#file.serverfile#">
<!-- END NEW LOGIC -->	

<!-- BEGIN DELETE or NONE LOGIC -->
	<!-- but what if we are supposed to delete? -->	
	<cfelseif (evaluate("usepic" & text_seq) is "delete") or (evaluate("usepic" & text_seq) is "none")>	
	<!-- begin sub-condition logic -->
		<!-- if there is an old file, then we delete it -->
		<cfif op is not "">
			<cffile action="DELETE" file="#s_ptag_serverpath1##op#">
		</cfif>
	<!-- end sub-condition logic -->	
	<!-- but we are still in delete mode, so we need to set the variuble to nothing -->
	<cfset "picture#text_seq#" = "">
<!-- END DELETE LOGIC -->	
</cfif>
	<!-- end of processing picture files -->

Open in new window

     



---------------------------------------------------------------------------------------------------------------------------
END   -     Q_text_inc_text1.cfml  (include for Q_text.cfm)
---------------------------------------------------------------------------------------------------------------------------
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39257881
(EDIT: Disclaimer, I'm still looking over the code, but ...)

A user could upload the same graphic in multiple sections and this would cause problems, if it is deleted or updated in the first or second instance.

Hm... but I still think changing the upload to "makeunique" instead of "overwrite" should solve that problem. If the uploaded file names are always unique, then deleting one shouldn't affect any other instances.  For example:

* User uploads a graphic for section 1 / #picture1#
   Final file name: myGraphic.jpg

* User uploads same graphic for section 2 / #picture2#
   Final file name: myGraphic1.jpg <=== file already exists, so CF makes it unique

* User uploads same graphic for section 3 / #picture3#
   Final file name: myGraphic2.jpg <=== file already exists, so CF makes it unique

Now the user deletes the graphics from section 1. The application deletes ONLY "myGraphic.jpg". The others are unaffected, because they point to different file names: myGraphic1.jpg, myGraphic2.jpg
0
 

Author Closing Comment

by:btintermedia
ID: 39258193
wow - I didn't think that it could actually be just that simple...but that makes it work! Thank you so much!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39258216
Glad I could help :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now