PHP: File access with umlauts under Windows

Files on web servers should always be stored without spaces (not "this is an image.jpg"), without umlauts or special characters (not "football.jpg"), without backslashes (not "work\car.jpg"), and in lowercase (not "test.JPG"). Recently, however, for a client project, I had to access and process a large number of predefined files with arbitrary filenames.


Linux systems allow access to files with umlauts and special characters by default, so that no special features have to be considered here. It looks completely different on Windows systems: Here you have to use some tricks and tap into the COM interface. First of all, you include the required extension in php.ini

[COM_DOT_NET]
extension = php_com_dotnet.dll

one. Now the very helpful helper class WinfsUtf8 is used, which greatly simplifies access to the COM objects and maps almost all PHP functions that affect files. After integrating the file with

require_once('WinfsUtf8.php');

you have all possibilities of file access, for example you get

file_exists('ä.jpg');

incorrectly false, whereas

Patchwork\PHP\Override\WinfsUtf8::file_exists('ä.jpg');

returns true.

Back