Last active
August 12, 2018 13:28
-
-
Save Mosharush/1d975ab0ecf516de0468ef0edc207b9c to your computer and use it in GitHub Desktop.
Wordpress - Fix images names encoded utf8 (gibberish)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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