Robert,
        At first glance, I thought this would work, but after looking
closely at the code, it does nothing more that what makeunique already
does, just adds a 1 to the end of the file name if not unique, thus each
time you use the routine, you end up with a file name that increases in
length by 1 char.  I may be able to adapt what you sent, by grabbing the
number at the end of upl_fle_nme, taking a val, increment that, and
replace the number into the name and then checking for prior existence.
So you have still helped me go in the right direction.

Jerome

-----Original Message-----
From: Robert Harrison [mailto:rob...@austin-williams.com] 
Sent: Friday, January 09, 2009 12:19 PM
To: cf-talk
Subject: RE: File upload and make unique

Assuming you are uploading from a form and the name of the file field is
"file", the routine below will do it. You will need to rename the paths
as
necessary. This routine will:

 1) Rename the file with incremental numbers (1, 2, 3, etc)
 2) Ensure the file name uses only standard characters (so it can be
used in
URL strings if you want to link to the file)
 3) Report back the final uploaded file name as the variable "upl_file"
 4) Prevent users from uploading dangerous file types (.cfm, .com, .exe,
etc.)

Hope this helps.


        <!--- ***************** ensures file name will be a legal name
having no special characters ************************** --->
        <cfset upl_file_nme="#ListFirst(serverfile,".")#">
        <cfset upl_file_ext="#ListLast(serverfile,".")#">
        <cfset upl_file_nme="#ReplaceList(trim(upl_file_nme), " ,]'",
",,")#">
        <cfset
upl_file_nme="#REREPLACE("#upl_file_nme#","#chr(8226)#","","all")#">
        <cfset upl_file_nme="#REReplace (upl_file_nme,
"[##""%/\\*?<>|:$'&@,(){}~`^!+;=[]", "", "all")#">
        <cfset upl_file_nme2="#upl_file_nme#">
        <cfset new_file="#upl_file_nme#.#upl_file_ext#">

        <cfif new_file is not "#serverfile#"> <!--- if the file name has
changed --->
                <cfdirectory action="list" directory =
ROOT\YOUR_PATH_HERE\"
name="checkfile" filter="#new_file#">
                <!--- renames file until name is unique --->
                <cfif checkfile.recordcount gt 0>
                        <cfset unique=0>
                        <cfset fcount=1>
                        <cfloop condition="unique neq 1">
                                <cfset
upl_file_nme2="#upl_file_nme##fcount#">
                                        <cfdirectory action="list"
directory
= ROOT\YOUR_PATH_HERE\" name="checkfile"
filter="#upl_file_nme2#.#upl_file_ext#">
                                <cfif checkfile.recordcount eq 0>
                                        <cfset unique=1>
                                        <cfbreak>
                                <cfelse>
                                        <cfset fcount=#fcount#+1>
                                </cfif>
                        </cfloop>
                </cfif>
                <cfset upl_file="#upl_file_nme2#.#upl_file_ext#">
                <cffile action="rename" source
ROOT\YOUR_PATH_HERE\#serverfile#" destination
ROOT\YOUR_PATH_HERE\#upl_file#">
        <cfelse>
                <cfset upl_file="#serverfile#">
        </cfif>
<cfelse>
        <cfset upl_file="">
</cfif>
<!--- ***************** end of file rename routine
*************************** --->






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:317656
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to