Link to home
Start Free TrialLog in
Avatar of jturkington
jturkington

asked on

UPLOADING / RENAMING A FILE

We are having an issue when we upload a file to our website in that it is not renaming the file correctly and is crashing out.
The original file is successfully uploading with its original name but is not renaming to the value we want. Is this because the file is not fully uploaded before trying to rename it ? or is it our renaming convention that is causing the issue do we need to use UUID function maybe ? The security on the folder it is uploading to has more than enough permissions, heres the code:  -

<cfif IsDefined("Process")>
<CF_Random_CVIDGen LENGTH="10" CHARSET="AlphaNumeric" UCASE="yes" RETURNVARIABLE="CVUniqueID">

<cfif form.CVFile neq "" and #UserDetails.CVLink# eq "">
<cfif cgi.CONTENT_LENGTH lt 200000>
<!--- first actually upload the file --->
         <cffile action="upload"
                 filefield="CVFile"
                 destination="D:\WWWRoot\www\uploads\"
                 nameconflict="Makeunique">
        <!--- now create a temporary holder for the attachment later on --->
        <cfset Filename = "#cffile.clientfilename#">
            
            <cfset acceptedExtensions="doc,txt,text,rtf,pdf">
            <cfset ext=ListLast(cffile.ServerFile,".")>
            
            <!--- check the file types of the file --->
            <cfif not ListFind(acceptedExtensions,ext)>
<cffile action="delete" file="D:\WWWRoot\www\uploads\#file.ServerFile#">
                  <cfset errormessage = errormessage &
                  "<li style=color:red><font class=mainBlack>Please attach a valid CV.</font></li>">
            <cfelse>
            <!--- its a good file --->
            <cffile action = "rename"
                     source = "D:\WWWRoot\www\uploads\#file.ServerFile#"
                     destination = "D:\WWWRoot\uploads\#UserDetails.Email##CVUniqueID#.#serverFileExt#">
                        
            <cfset FileUploaded = "D:\WWWRoot\uploads\#UserDetails.Email##CVUniqueID#.#serverFileExt#">

            <cfquery name="UpdateCandidates" datasource="Datasource">
            update Candidates
            set CVLink = '#FileUploaded#',
            Filename = '#Filename#',
            CVUpdated = '#DateFormat(Now(),"dd/mm/yy")# #TimeFormat(Now(),"HH:MM:SS")#'
            where CandID = #SESSION.Auth.CandID#
            </cfquery>
            </cfif>
            </cftransaction>
      <cfelse>
            <cfset errormessage = errormessage &
            "<li style=color:red><font class=mainBlack>File too Large. Cannot be greater than 200kb.</font></li>">
      </cfif>
      <cfelseif form.CVFile eq "" and #UserDetails.CVLink# eq "">
       <cfset errormessage = errormessage &
            "<li style=color:red><font class=mainBlack>Please attach your CV.</font></li>">
      </cfif>

Random ID Code (Random_CVIDGen)

<html>
<head>
<title>Random ID</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<cfparam name="ATTRIBUTES.Length" default="6">

<!--- types of characters to use in the password (default Uppercase, Lowercase letters and 0-9 --->
<cfparam name="ATTRIBUTES.CharSet" default="alpanumeric">

<!--- name of the variable to store the generated password (default RandomPassword) --->
<cfparam name="ATTRIBUTES.ReturnVariable" default="RandomPassword">

<!--- yes/no include uppercase characters in the password? (default yes)--->
<cfparam name="ATTRIBUTES.Ucase" default="yes">

<body>

<cfif NOT isnumeric(ATTRIBUTES.Length)>
    <cfthrow detail="The attribute <b>Length</b> must be a valid numeric value">
</cfif>

<!--- valid CharSets are handled as the defaultcase below --->

<!--- ATTRIBUTES.Ucase is only checked for as "YES" if it is NOT "YES" uppercase letters are simply not included
no errors will be thrown no matter what you specify as this attribute--->

<cfset alphaLcase  = "a|c|e|g|i|k|m|o|q|s|u|w|y|b|d|f|h|j|l|n|p|r|t|v|x|z">
<cfset alphaUcase = "A|C|E|G|I|K|M|O|Q|S|U|W|Y|B|D|F|H|J|L|N|P|R|T|V|X|Z">
<cfset numeric      = "0|2|4|6|8|9|7|5|3|1">

<!--- decide what cars to use in generating the password --->
<cfswitch expression="#ATTRIBUTES.CharSet#">
    <!--- Create only alpha passwords (NO NUMBERS ALLOWED) --->
    <cfcase value="alpha">
        <cfset charlist = alphaLcase>
        <cfif ATTRIBUTES.UCase IS "Yes">
            <cfset charList = listappend(charlist, alphaUcase, "|")>
        </cfif>
    </cfcase>
    <!--- Create Alphanumeric passwords --->
    <cfcase value="alphanumeric">
        <cfset charlist = "#alphaLcase#|#numeric#">
        <cfif ATTRIBUTES.UCase IS "Yes">
            <cfset charList = listappend(charlist, alphaUcase, "|")>
        </cfif>
    </cfcase>
    <!--- Create only numeric passwords --->
    <cfcase value="numeric">
        <cfset charlist = numeric>
    </cfcase>

    <cfdefaultcase>
        <cfthrow detail="Valid values of the attribute <b>CharSet</b> are Alpha, AlphaNumeric, and Numeric">
    </cfdefaultcase>
</cfswitch>

<cfparam name="ThisPass" default="">

<!--- each loop count gets one new character and adds it to the end of the password,
so loop from 1 to "the number set in the calling template in ATTRIBUTES.Length --->
<cfloop from="1" to="#ATTRIBUTES.Length#" index="i">

    <!--- pick a random number between 1 and the length of the list of chars to use --->
    <cfset ThisNum = RandRange(1,listlen(charlist, "|"))>

    <!--- get the character that is at the random numbers position in the list of characters --->
    <cfset ThisChar = ListGetAt(Charlist, ThisNum, "|")>

    <!--- append the new random character to the password --->
    <cfset ThisPass = ListAppend(ThisPass, ThisChar, " ")>

</cfloop>

<cfset ThisPass = replace(ThisPass, " ", "", "ALL")>
<cfset "Caller.#ATTRIBUTES.ReturnVariable#" = ThisPass>

</body>
</html>

Thanks for your help guys !!
SOLUTION
Avatar of mrichmon
mrichmon

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 mrichmon
mrichmon

You could also try doing a MOVE instead of a rename - which would in effect do the same thing, but may work when renaming doesn't.
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
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
ASKER CERTIFIED 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
Did any of these comments help you or are you still stuck?