How do I use filesystem functions in PHP, using UTF-8 strings?

后端 未结 9 2448
[愿得一人]
[愿得一人] 2020-11-22 13:26

I can\'t use mkdir to create folders with UTF-8 characters:


when I

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 13:47

    Using the com_dotnet PHP extension, you can access Windows' Scripting.FileSystemObject, and then do everything you want with UTF-8 files/folders names.

    I packaged this as a PHP stream wrapper, so it's very easy to use :

    https://github.com/nicolas-grekas/Patchwork-UTF8/blob/lab-windows-fs/class/Patchwork/Utf8/WinFsStreamWrapper.php

    First verify that the com_dotnet extension is enabled in your php.ini then enable the wrapper with:

    stream_wrapper_register('win', 'Patchwork\Utf8\WinFsStreamWrapper');
    

    Finally, use the functions you're used to (mkdir, fopen, rename, etc.), but prefix your path with win://

    For example:

    
    

提交回复
热议问题