Solved

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

Posted on 2013-11-14
4
145 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
4 Comments
 
LVL 2

Accepted Solution

by:
loki0609 earned 500 total points
Comment Utility
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
Comment Utility
BINGO! Thanks so much!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now