[Plugin: NextGEN Gallery] A solution for accented characters in uploaded filenames
-
Uploading files with hungarian accented filenames resulted in the images not appearing in the gallery. My not so elegant solution was to add this function in the current theme’s function.php:
function correct_filename($filename) {
$accented = array(“?”, “ü”, “ó”, “?”, “ú”, “é”, “á”, “?”, “í”, “?”, “ü”, “ó”, “?”, “ú”, “é”, “á”, “?”);
$non_accented = array(“o”, “u”, “o”, “o”, “u”, “e”, “a”, “u”, “i”, “O”, “U”, “O”, “O”, “U”, “E”, “A”, “U”);
$filename = str_replace($accented, $non_accented, $filename);
$characters = array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’, ‘-‘, ‘_’, ‘.’, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘&’);
$correct_filename = ”;
for($i=0;$i<strlen($filename);$i++) {
if(in_array($filename[$i], $characters)) {
$correct_filename .= $filename[$i];
} else {
$correct_filename .= ‘-‘;
};
};
return $correct_filename;
};This changes the hungarian accented characters to the non-accented versions and changes every character that is not in the allowed array to a dash.
In NextGen Gallery’s function file (wp-content/plugins/nextgen-gallery/admin/functions-php) I added the following line:
$filename = correct_filename($filename);Before this line:
$dest_file = WINABSPATH . $gallery->path . ‘/’ . $filename;
(Line 1085 in my case)This solved the problem.
Could the dev team solve this problem without hacks like this in future releases?
T.
- The topic ‘[Plugin: NextGEN Gallery] A solution for accented characters in uploaded filenames’ is closed to new replies.