Solved

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

Posted on 2013-11-14
4
159 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select distinct 25 122
Setting strict transport security header in header not working 1 126
SQL to update characters in table column 6 163
The Best Website Creation Tools 14 95
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

730 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