简体   繁体   中英

PHP hardlink non-English characters path

How can I hardlink a file inside the non-English directory?

function createDir($path) {
  if (!file_exists($path)) {
    createDir(dirname($path));
    mkdir($path, 0777);
  }
}

createDir(__DIR__.'/data2xml/南海釣魚台');

$src = "D:\\xampp\htdocs\\projectb/data1/pic/2003161613561.jpg";
$dest = "D:\\xampp\htdocs\\projectb/data2xml/南海釣魚台/2003161613561.jpg";

link($src, $dest);

Warning: link(): No error in D:\\xampp\\htdocs\\projectb\\test.php on line 17

link ( ???, ??? ) ...\\test.php:17

copy($src, $dest) can work but it takes too much time.

test.php works fine on the other win10 machines. How can I debug this? Thanks.

Moving a file is faster than copying a file.

rename() can work on non-English characters.

Hardlink to a English temp file and then move it to the destination.

$tmp = __DIR__.'/tmpfile';
link($src, $tmp);
rename($tmp, $dest);

or upgrade to php7.2.7+

https://www.php.net/ChangeLog-7.php#7.2.7

Fixed bug #76335 ("link(): Bad file descriptor" with non-ASCII path).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM