Use the md5_file () function with emphasis on the file name

In my PHP script, I use the function md5_file()to return the md5 key for each parsed file.

However, when a file has an accent in the file name, the function md5_file()cannot read the file.

//filename: Flash_Conquête_Galactic.txt
Warning: md5_file(.....): failed to open stream: No such file or directory in

I tried to use a function iconv()or function utf8_encode(), but both results had absolutely no result.

Is there a way to fix this problem without changing the file name?

+4
source share
1 answer

It looks like $ filename might have been encoded by UTF-8 in some way, perhaps your IDE / editor.

Try it...

    // Your filename
    $filename = 'Flash_Conquête_Galactic.txt';

    // Decode the string to ISO-8859-1.
    $filename = utf8_decode($filename);

    // Generate a hash of the files contents.
    echo md5_file($filename);
-1
source

Source: https://habr.com/ru/post/1570018/


All Articles