Work with rename function in PHP

There is a file inside the directory, and I'm trying to use rename (arg1, arg2) to rename the file arg1.

However, the arg1 file contains Asian letters, and I get a message that the file is not available.

how can i solve this problem

thanks

$elements = scandir($dir); foreach ($elements as $key => $value) { rename("./$value", "$newname"); } 
+4
source share
1 answer

Remember to set the paths correctly:

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

To be less abstract, suppose $ dir is something like "/ home / someuser / somefiles" and your script is on the page /var/www/script.php, you get all the files (for example, " oldname.txt ") from scandir ($ dir), so the absolute path to the file is" /home/someuser/somefiles/oldname.txt ", but you pass" ./oldname.txt "to the rename function, which is actually" /var/www/oldname.txt "

+1
source

All Articles