I'm trying to batch rename files in a folder with PHP. It's mostly working, though I'm having problems with accented characters.
An example of a filename with accented characters is ÅRE_GRÖN.JPG.
I would like to rename that file to ARE_GRON.JPG.
If I read the files in like this:
<?php
$path = __DIR__;
$dir_handle = opendir($path);
while ($file = readdir($dir_handle)) {
echo $file . "\n";
}
closedir($dir_handle);
...And the page displays ÅRE_GRÖN.JPG.
If I add header('Content-Type: text/html; charset=UTF-8'); to the beginning of my script, it displays the correct file name, but the rename() function seems to have no effect either way.
Here's what I've tried:
while ($file = readdir($dir_handle)) {
rename($file, str_replace('Ö', 'O', $file)); # No effect
rename($file, str_replace('Ö', 'O', $file)); # No effect
}
Where am I going wrong?
Do say if you believe I'm using the wrong tool for the job. If anyone knows how to achieve this with a Bash script, show me. I have no Bash chops.