• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

# in file name

Explorer ,
May 11, 2009 May 11, 2009

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

468

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , May 11, 2009 May 11, 2009

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

...

Votes

Translate

Translate
Valorous Hero ,
May 11, 2009 May 11, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2009 May 17, 2009

Copy link to clipboard

Copied

LATEST
#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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation