Solved

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Field that has HTML displays the code instead of the text in html 16 80
CA single sign on 2 89
Grunt No Clean Targets 6 157
aws pricing 2 46
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

803 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