简体   繁体   English

PHP硬链接非英文字符路径

[英]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():第 17 行 D:\\xampp\\htdocs\\projectb\\test.php 中没有错误

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

copy($src, $dest) can work but it takes too much time. copy($src, $dest) 可以工作,但需要太多时间。

test.php works fine on the other win10 machines. test.php 在其他 win10 机器上运行良好。 How can I debug this?我该如何调试? Thanks.谢谢。

Moving a file is faster than copying a file.移动文件比复制文件快。

rename() can work on non-English characters. rename() 可以处理非英文字符。

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+或升级到php7.2.7+

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

Fixed bug #76335 ("link(): Bad file descriptor" with non-ASCII path).修复了错误 #76335(具有非 ASCII 路径的“链接():错误的文件描述符”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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