I have a very simple file upload that allows users to upload PDF files. On another page I then reference those files through an anchor tag. However, it seems that when a user upload a file that contains the pound sign (#) it breaks the anchor tag. It doesn’t cause any type of Coldfusion error, it just can’t find the file. If I remove the #, it works just fine. I am sure there are a number of other characters that would have this same issue.
I’ve tried putting URLEncodedFormat() around the file name inside the anchor but that doesn’t help. The only other thing I could think of was to rename the file each time it was uploaded and remove the “#” character (and any other “bad” character).
There has got to be an easier solution. Any ideas?
If you control the file upload code try validating the string with
Otherwise if you are comfortable with regex I would suggest something like the previous posters are commenting on
These samples assume you will add the “.pdf” and only allows letters and numbers. If you need underscores or the period it would look like this…
I am not a regex guru, if I have one of these wrong I am sure several will jump in and correct me 🙂