2 Replies Latest reply on May 17, 2009 1:33 PM by BKBK

    # in file name

    Kkofal

      I had a user who uploaded a file with an illegal Char ("#") in the filename.  So obviosly the file wouldn't load up when selected.

       

      Now the boss wants to check for illegal chars prior to uploading files, not an unreasonable request IMHO, however the code:

       

      <CFIF #Find ("#", file.ServerFile)# EQ 1>

           do this

      </CFIF>

       

      does not properly process.

       

      The error occurred in C:\inetpub\wwwroot\Predator2\action\attachadd_act.cfm: line 30
      28 :           </cfquery>
      29 :           
      30 :           <cfif #find("#", FILE.ServerFile)#>
      

       

      Same results with FindNoCase, FindOneOf

        • 1. Re: # in file name
          ilssac Level 5

          You need to escape the # character when not using it to define variables in CFM.

           

          I.E.

          <cfif Find("##",file.serverFile) EQ 1>
          

           

          P.S.

          NOTE:  You also do not need the # characters around the function in the if statement.  Generally you only need to use the # characters around variables and functions when you want the results rendered to output.  Otherwise inside of functions and tags, CF knows what are variables and functions.

           

          Finally, A # character is not an illeagle character in a file name, it is just one that needs to be escaped like was done above.  So rather then denieing the file you could change the name to double the # character so that CFML can process the file, your choice.

          • 2. Re: # in file name
            BKBK Adobe Community Professional & MVP
            #Find ("#", file.ServerFile)#

             

             

            1) A file name may indeed contain #, as Ian has said;

            2) # is char(35);

            3) The file structure has been deprecated in favour of cffile.

             

            Taking these 3 considerations into account, you get

             

            find(chr(35), cffile.serverFile)