Piwik, PHP, double-byte files and Windows

Please forgive me if this has been covered before, I have searched the forums and found nothing.

Currently I serve pages from a Windows platform (Server 2003, and Win7). Sometimes I have filenames in Japanese, and while I can download them directly, I cannot get PHP to recognize their existence. A PHP script that fetches a file and sends it to the user works fine with single-byte filenames, but fails to find double-byte names.

Now, this appears to be a problem with PHP and Windows, different browser encodings and OMG the rabbit hole goes on FOREVER.

As an example:
fetch.php?file=test.txt <- PHP script send file, Piwik code in script functions fine.
fetch.php?file=テスト.txt <- PHP script can’t find file, Piwik code may function but it’s useless.

My question is: How can I use Piwik to track file downloads if no PHP script will work with a Japanese filename? Can anyone offer any tips, clues, pointers, links, books or anything? I’m sort of stumped.

Seems to be a general problem of PHP on windows. See Working with Japanese filenames in PHP 5.3 and Windows Vista? - Stack Overflow and php readdir problem with japanese language file name - Stack Overflow for some solutions.

If you’re mixing UTF-8 and UCS-2, then you’ll need to use something like iconv() to convert your filenames.

Example:


$filename = iconv('UTF-8', 'UCS-2', $_GET['file']);

(Security considerations left as an exercise for the reader.)