There is a file within the directory and I am trying to use rename( arg1, arg2 ) to rename the arg1 file.
However, the arg1 file contains Asian letters and I get the message that the file is not available.
how can I solve this issue
thanks
$elements = scandir($dir);
foreach ($elements as $key => $value)
{
rename("./$value", "$newname");
}
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 (eg "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"
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.