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
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
...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.
Copy link to clipboard
Copied
#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)