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

Posted on 2005-03-09
Medium Priority
Last Modified: 2013-12-24
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.
Question by:Ike23
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 13498307
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>

LVL 25

Expert Comment

by:James Rodgers
ID: 13498400
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#">

Expert Comment

ID: 13600431
did either solution work for you?

Author Comment

ID: 13603300
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.

Accepted Solution

kyle1830 earned 1000 total points
ID: 13605187
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question