Responsive file manager v9 uploading arabic file's name issue

948 Views Asked by At

I am using now Responsive file manager v9 as a plugin of tinymce, the version of tinymce is 4.7.4, PHP version is 5.5. The problem I was trying fix the uploaded arabic files' name issue, RFM doesn't upload files which their names is arabian with correct names.

The names of images I choose to test are "vvv" , "اختبار", "اختبار - Copy" all of them are 'jpg' after I upload the files those has an arabic names they give the result like this:

اختبار.jpg ===> ط§ط®طھط¨ط§ط±.jpg

اختبار - Copy.jpg ==> ط§ط®طھط¨ط§ط± - Copy.jpg

however, in config.php is the mb_internal_encoding function is UTF-8.

I tried use iconv by convert between utf-8 to cp1256 in UploadHandler.php line 1097 like this:

move_uploaded_file($uploaded_file, iconv("utf-8", "cp1256",$file_path));

instead of

move_uploaded_file($uploaded_file, $file_path);

and it allowed to upload the files with their arabian names but they appeared in RFM browser with ?????? and ????? - Copy and no thumbs images in browser, however the thumb folder had the images and the image اختبار.jpg didn't upload correctly and made it bad. only English files' names work fine.

I worked in all php files and I used base64_encode, and I tried change the the encoding in config.php but nothing work.

Does anyone have any idea to fix that ?

2

There are 2 best solutions below

0
On

You don't want to mess with UploadHandler.php. All of the preprocessing of the upload happens in upload.php, including massaging the filename in the function fix_filename in utils.php. By the time it gets to UploadHandler, the filename has already been modified so iconv and friends won't work. Take a look at fix_filename and try manipulating the string there:

/**
* Cleanup filename
*
* @param  string  $str
* @param  bool    $transliteration
* @param  bool    $convert_spaces
* @param  string  $replace_with
* @param  bool    $is_folder
*
* @return string
*/
function fix_filename($str, $config, $is_folder = false)
{
    if ($config['convert_spaces'])
    {
        $str = str_replace(' ', $config['replace_with'], $str);
    }

    if ($config['transliteration'])
    {
        if (!mb_detect_encoding($str, 'UTF-8', true))
        {
            $str = utf8_encode($str);
        }
        if (function_exists('transliterator_transliterate'))
        {
            $str = transliterator_transliterate('Any-Latin; Latin-ASCII', $str);
        }
        else
        {
            $str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
        }

        $str = preg_replace("/[^a-zA-Z0-9\.\[\]_| -]/", '', $str);
    }

    $str = str_replace(array( '"', "'", "/", "\\" ), "", $str);
    $str = strip_tags($str);

    // Empty or incorrectly transliterated filename.
    // Here is a point: a good file UNKNOWN_LANGUAGE.jpg could become .jpg in previous code.
    // So we add that default 'file' name to fix that issue.
    if (strpos($str, '.') === 0 && $is_folder === false)
    {
        $str = 'file' . $str;
    }

    return trim($str);
}
0
On

The reason why you're getting "?????? and ?????" is because you have to change the collection set of your database as well which could be UTF8 General CI and than save the file name (without iconv()) and move the file with file_name by using iconv()