flash
flash

Reputation: 85

PHP rename failed for foldername with utf-8 turkish charset string

<?php

$oldname = 'D:\a\file.zip';
$newName = 'D:\a\öÖçÇ\İ\file.zip';
//$newName = 'D:\a\ooCC\i\file.zip'; it's work

rename($oldname, $newName);

?>

Error:

Warning: rename(D:\a\file.zip,D:\a\öÖçÇ\İ\file.zip): The system cannot find the path specified. (code: 3) in C:\Users\Desktop\rename.php on line 9

I tried "url_encode", "iconv" however didn't work it.

Upvotes: 2

Views: 176

Answers (1)

flash
flash

Reputation: 85

The file path needed to be encoded as UTF-16 for Windows to recognise it. Since my PHP source code is saved with encoding "UTF-8", I used this:

$oldname = 'D:\a\file.zip';
$newName = 'D:\a\öÖçÇ\İ\file.zip';
$newName = iconv("UTF-8", "UTF-16", $newName);

$copyIslem = copy($oldname, $newName);

Upvotes: 1

Related Questions