Solved

A # sign in filenames is causing an issue with url.

Posted on 2013-11-14
4
164 Views
Last Modified: 2014-10-24
I've got a little php script which reads the files in a directory then creates and displays it as a link to the file in a web page. Example; a file in the directory is named abcdef.pdf, so my script reads that and writes <a href="abdcef.pdf">abcdef.pdf</a>. Here's the issue, on this particular Unix server some of the file names include a # sign and spaces, like abc# def.pdf. The spaces aren't an issue but that # sign sure is. Does anyone know if there's a way to include a # sign in the url without it being some sort of instruction to the browser? I'll keep googling. Again, this is on a SCO Openserver 6 Unix server running apache webserver. I suppose I could talk to the customer about renaming the ~3000 files with a # in the name.
0
Comment
Question by:tjb1
[X]
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
4 Comments
 
LVL 2

Accepted Solution

by:
loki0609 earned 500 total points
ID: 39650401
Number/Pound Sign (#) - this character is used to delimit a URI from a fragment identifier (aka bookmarks), so the URI "http://localhost/foo#bar.doc" could be misinterpreted as the URI "http://localhost/foo" with a bookmark of "bar.doc".

that being said i did a "very quick" test of

$file = urlencode($filename);

Open in new window


this worked if the file was something like test#tees.pdf

but if there was a space in the file name it didn't work. This is because urlencode replaces spaces with the + symbol which it doesn't like when looking for a file:)

so instead use

$file = rawurlencode($filename);

Open in new window


which replaces spaces with %20 instead of a + symbol and it works.
0
 

Author Comment

by:tjb1
ID: 39650962
BINGO! Thanks so much!
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

690 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