开发者

special characters in file/folder names on Linux; Rename php function not working

开发者 https://www.devze.com 2023-01-01 21:06 出处:网络
I am using a function Rename() (php) to move some images from one folder to another. The destination folder has special characters in them.

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消