tags:

views:

150

answers:

1

I have made a php script that iterates through files in a directory and outputs links to them. The file names are in Spanish so some contain characters like á, é, etc.

My script works fine in my dev machine which is windows+apache+php, however it does not work in my hosting's server which is linux+apache+php, it does not find the file.

Some searching has suggested to use urlencode(), however when I do this it breaks under my dev machine so it is not acceptable to me, although I have not tried it in my webserver.

EDIT: More details about error on dev machine when using urlencode().

There seem to be 2 errors, one is when the file name has characters like á, é, etc. And the other one when the file name has whitespaces.

A file name with whitespaces (ie. 'Calidad Total .doc') gets the following link http://localhost/temarios/docs/Calidad+total+.doc which gives me a 404 file not found error. Replacing the '+'s for ' 's in the address bar makes it work fine.

A filename with accented chars (ie. Economía.doc) gets the link http://localhost/temarios/docs/Econom%EDa.doc which gives me a 403 Forbidden error. Replacing the '%ED' for an 'í' in the address bar makes it work fine.

I have tested in Firefox 3 and IE8 windows 7 beta and the same thing happens in both browsers.

+1  A: 

The reason you should urlencode them is because URLs must consist solely of printable US-ASCII characters.

"URLs are written only with the graphic printable characters of the US-ASCII coded character set."

It may be wise for you to post details of the error you receive on your dev machine and figure out what's wrong there.

Joe Holloway