Skip to content

Instantly share code, notes, and snippets.

@Mosharush
Last active August 12, 2018 13:28
Show Gist options
  • Save Mosharush/1d975ab0ecf516de0468ef0edc207b9c to your computer and use it in GitHub Desktop.
Save Mosharush/1d975ab0ecf516de0468ef0edc207b9c to your computer and use it in GitHub Desktop.
Wordpress - Fix images names encoded utf8 (gibberish)
<?php
$it = new RecursiveDirectoryIterator(".");
$extAllow = Array ( 'jpeg', 'jpg' );
foreach( new RecursiveIteratorIterator($it) as $img ){
$ext = explode( '.', $img );
$ext = array_pop( $ext );
if (! in_array( strtolower( $ext ), $extAllow ) ){
continue;
}
$uncodedImg = urldecode( urldecode( $img ) );
if( $uncodedImg != $img ){
if( rename( $img, $uncodedImg ) ){
echo 'Image saved: ' . $uncodedImg .'<br/>';
} else {
echo 'Can\'t save image: ' . $uncodedImg .'<br/>';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment