views:

305

answers:

2

I am using a function Rename() (php) to move some images from one folder to another.

The destination folder has special characters in them.

However, when doing this on the server I get the error that the folder isn't found with the name. And in that error, the folder names special characters are replaced with Squares:

Warning: rename(../temp_images/668635375_1.jpg,../ad_images/B�tar/thumbs/668635375_1.jpg)
[function.rename]: No such file or directory in /var/www/etc....

It works on my local machine though (windows xp).

Any ideas? Troubleshooting tips?

Thanks

+2  A: 

I assume this is an encoding problem at some point.

However, using non-ASCII characters in file names is a slippery slope anyway.

I always recommend (since another SO user made me aware of that great and simple idea) that if you can, urlencode() file names and urldecode() them when serving them to the public. This will give you a file name consisting of characters that work on every file system known to me, and can hold any Unicode character.

Pekka
So what would the names of the folders be then? I don't quite understand it... Do you mean I should urlencode the folder names?
Camran
@Camran yup, that's the idea. Mind you: It *is* possible to store UTF-8 characters in all modern file systems, so you can achieve this without converting anything, but then, you'll have to get the encodings right everywhere. The urlencode() suggestion is a way to work around that hassle, and to make it more easily portable across platforms.
Pekka
A: 

It is likely an encoding problem: it could be even in the source (in which encoding those "special" characters are written in, in the php source?...), or somewhere else, or both. By "somewhere else" I mean, it could be the right encoding int the string, parsed badly by php, or parsed correctly, but "passed" wrongly from rename() and the underlaying system call (/filesystem) that performs the actual renaming.. In my experience, bad things are likely to occur if you use "special" characters for folders/files that can be read by different systems or accessed through different API... So: do not use "special" characters in folders/files that must be accessible by an http server / php script on a machine system that could be different from the one that "created" the folder/file.

A reading to this could help.

ShinTakezou
moreover, as noted, you can't put those so easily in an url, in case you need that: you must encode them properly wth the %NN notation (urlencode does it and more).. this will preserve encoding correctly from http requests, nonetheless it still makes no sure it matches the encoding you hardencoded in the source or whereever else, and/or the encoding of the folder name; by the way, can you access it by the client like mysite.com/odddir%80%90%6F or whatever %.. you need?
ShinTakezou