I am trying to implement a file upload utilizing Plupload and its chunk
methodology that needs to be compatible with older versions of ColdFusion as
far back as version 5. 

So far I have had success in the test environment but have found an issue I
can't seem to solve and that is what happens when the user opens a new
browser window and proceeds to upload the same file OR file with the same
name as is already uploading.  There does not seem to be any way to know
that it is the same or different file when the names are the same.

I can solve it for different sessions or users by temporarily attaching the
session ID to the file name for that session but if the same user session
opens another browser window and starts uploading the file the resulting
file will be corrupted since too many chucks in the wrong order will be
appended.

Does anyone have some insight?  Here is the test code I have been using.

<cfset thedir = "c:\webs\uploads\">
<cfset chunkdir = "c:\webs\uploads\chunks\">
<!--- We are executing a normal upload (ie, the entire file at once). --->
<cfif NOT IsDefined("form.chunks")>
        <!---
                // do a normal file upload process
        --->
</cfif> 
<cfelse>
<!--- 
        // Since we are dealing with chunks, instead of a full file, '
        // we'll be appending each chunk to the known file
 --->

<cffile action="UPLOAD"
        filefield="file"
          destination="#chunkdir#"
          nameconflict="MAKEUNIQUE"> 
                
        <cffile action="READBINARY"
file="#chunkdir##trim(cffile.serverfile)#" variable="thechunk">
        <cffile action="DELETE" file="#chunkdir##trim(cffile.serverfile)#">
        <cfif Fileexists("#chunkdir##trim(form.name)#")>
                <cffile action="APPEND" file="#chunkdir##trim(form.name)#"
output="#thechunk#" addnewline="no">
        <cfelse>
                <cffile action="WRITE" file="#chunkdir##trim(form.name)#"
output="#thechunk#" addnewline="no">
        </cfif> 
        <cfif Val(form.chunk) eq Val(form.chunks)-1>
        <!--- 
                // If this is the last of the chunks, the we can do checks
and adjustments 
                // for other files of the same name then move/rename the
file to the
                // completed uploads folder for processing. 
        --->    
</cfif>
</cfif>
<!--- if everything is OK and there are no errors Return a success message.
--->
<cfheader statuscode="201" statustext="Created">

 

Dennis Powers
UXB Internet - A website Design and Hosting Company
P.O. Box 6028, Wolcott, CT 06716 - T:203-879-2844
W: http://www.uxbinternet.com
W: http://www.ctbusinesslist.com




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:358786
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to