Reputation: 343
we have a file that have persian name, like:
ایران.jpg
our problem is that php unable to copy or rename this file by orginal name, meaning if file name does not have fully english character, result is like this:
ط§ط´ط±ع©طھ ظ…ظ„غŒ ظ¾ط®ط´ ظپط±ط¢ظˆط±ط¯ظ‡ ظ‡ط§غŒ ظ†ظپطھغŒ-04ط¢ط¨ط§ظ†.jpg
some articles recommendation for use of iconv function, like:
$fn = iconv("CP-1252", "UTF-8", $file['name']);
we use of that method, but the solution not work.
Upvotes: 2
Views: 1995
Reputation: 3860
You Should Choose Right Code Page. This Code Works In Windows For Arabic/Persian Names:
$newname = iconv("UTF-8", "CP1256//IGNORE","گچپژ");
echo rename("1.txt", $newname);
Upvotes: 1
Reputation: 343
In fact, we have a conversion from UTF-8 to UTF-8, Not ridiculous?
Value of $_FILE['name'] is UTF-8 and we try to set that character-set to UTF-8!!!
Our problem is that we have entered into with utf-8, but saved by unknown encoding!
I think Php is a serious bug, if you think opposite, active persian language in your windows os and try to make a folder by persian character by PHP (like ایران), and use of all method that you think work!
If it was, you did a great job, but if ...
Upvotes: 0
Reputation: 1707
You need to specify the correct character set to iconv from which to convert the string. Something like this:
$fn = iconv("<persian-character-set>", "UTF-8", $file['name']);
You may want to add additional options to the output character set like TRANSLINT and/or IGNORE:
$fn = iconv("<persian-character-set>", "UTF-8//TRANSLIT//IGNORE", $file['name']);
See http://php.net/manual/en/function.iconv.php for details on these options.
Upvotes: 2