4

目录中有一个文件,我正在尝试使用 rename( arg1, arg2 ) 重命名 arg1 文件。

但是,arg1 文件包含亚洲字母,我收到该文件不可用的消息。

我该如何解决这个问题

谢谢

    $elements = scandir($dir);


foreach ($elements as $key => $value) 
{

    rename("./$value", "$newname");

}
4

1 回答 1

1

Be sure to put the paths correctly:

$elements = scandir($dir);
foreach ($elements as $key => $value) {
    rename($dir.'/'.$value, $dir.'/'.$newname);
}

To be less abstract, assume $dir is something like "/home/someuser/somefiles" and your script is located at "/var/www/script.php", you are getting all files (e.g. "oldname.txt") from scandir($dir), so the absolute path to the file is "/home/someuser/somefiles/oldname.txt", but you are passing "./oldname.txt" to the rename function, which is in fact "/var/www/oldname.txt"

于 2012-08-13T22:20:27.033 回答