0

I know there are similar questions about this topic, but unfortunately none have solved my problem

I simply want to rename a file that has an Arabic filename

For example a file named 'ملف.txt' definetly existing in the same folder I have my script in

rename('ملف.txt','File.txt');

This Gives: rename(ملف.txt,File.txt) [function.rename]: No such file or directory

After some googling I learned that I must use:

$temp = iconv('utf-8', 'cp1252', 'ملف.txt');

rename($temp,'File.txt');

This Gives:

rename(,File.txt) [function.rename]: Illegal byte sequence

I also tried using urlencode but that gave:

rename(%D9%85%D9%84%D9%81.txt,File.txt) [function.rename]: No such file or directory

Some help would be appreciated

Haz
  • 203
  • 6
  • 15
  • 2
    Answer may largely depend on OS. Can you update question with that information? – Leri Jul 04 '13 at 13:59
  • Hey @PLB thanks for ur time, Im on Windows using local xamp server – Haz Jul 04 '13 at 14:18
  • http://stackoverflow.com/questions/11243863/php-rename-faled-for-filename-with-utf-8-arabic-charset-string – Andrej Bestuzhev Jul 04 '13 at 14:33
  • Yes I read that one @AndrejBestuzhev but I didn't quite understand what he did, he talks about changing something in his code, but I don't have any code just this simple command, I did try basename() though didn't work either – Haz Jul 04 '13 at 14:43
  • Did you paste filename in your code, or you read it into variable before? – Andrej Bestuzhev Jul 04 '13 at 14:51
  • @AndrejBestuzhev I tried both, even from a database, all didn't work – Haz Jul 04 '13 at 15:05

2 Answers2

1

write this code :

$newName  = iconv("utf-8", "cp1256","السلام عليكم.txt");
rename("file.txt", $newName);
  • Can you elaborate a bit more on the answer? At first it's hard to tell what is your solution. I believe it's the encoding used? Can you maybe also add your result of running the code sample? Did actually work? – Michal Trojanowski Dec 10 '18 at 22:04
  • This method renames a file to a name in Arabic encoding and is valid with the Windows system only – mohamed isam Dec 11 '18 at 11:18
0

This Sample Should Helps ,I Test Bellow Code And It Works In Windows For Arabic/Persian Names:

iconv("UTF-8", "CP1256//IGNORE","گچپژ");
echo rename("1.txt", $newname);
MSS
  • 3,520
  • 24
  • 29