• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

Problem with downloading file that contains the & character in the file name

I have a simple page that allows a user to upload a file from their pc to the server and then displays the files with links on a web page.  Everything is working fine except a few of the files would show a "page cannot be found error".  I figured out that the reason was the & character in the filename causing the URL to not find the file and think it was another URL variable.  I am using the URLENDCODEDFORMAT() function and it still doesn't work.  I have to rename the file to take out the & character and it works but I don't want my users to have to remember to do this.  Is there another CF function that will replae the & character witha URL friendly string?  Thanks.
  • 3
1 Solution
a suggestion would be to have the URLEncodedFormat during the file upload.

File "Bob&Tom.doc"  would then be saved as "Bob%26Tom.doc"

then to get the file would be something like: <a href="myfiles/bob%26tom.doc">Bob & Tom</a>

James RodgersWeb Applications DeveloperCommented:
try this after teh file has uploaded but before you enter the file name in teh db

<cfloop list="&" index="idx"> <!--- add any symbols you want replaced separated by a comma (,) --->
<cfif refind(idx,FILE.serverFileName)>
<cfset var=rereplace(str,idx,"","all")>
<cffile action="RENAME" source="#expandPath('.')#\#FILE.serverFileName#" destination="#expandPath('.')#\#var#">
did either solution work for you?
Ike23Author Commented:
Not really since the files have already been uploaded and the user is upset that the pages are "broken".  I was hoping there was a way to trick the browser or the server to pick up the file even when there is a '&' sign.  I guess I would have to use the encoded value when I pass the variable to the action page and then before I go get the file translate the 'encoded &' sign back to plain'&' so the server could find the actual name.  Any idea how to do this?  Thanks.
Here is a possible solution.  I just tried both and it worked.

file name: this&that.txt

<a href="#urlencodedformat('this&that.txt')#">file</a>
<a href="#replace("this&that.txt","&","%26")#">file</a>


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now