title: UTF-8, PHP, Win7 - Is there a solution now to save UTF-8-filenames on Win 7 using php?
body: <blockquote>
    <p>Update: Just to not make you reading through all: PHP starting with
    7.1.0alpha2 supports UTF-8 filenames on Windows. (Thanks to Anatol-Belski!)</p>
  </blockquote>
  
  <p>Following some link chains on stackoverflow I found part of the answer:
  <br><a href="https://stackoverflow.com/a/10138133/3716796">https://stackoverflow.com/a/10138133/3716796</a>  by Umberto Salsi
  <br>(and on the same question: <a href="https://stackoverflow.com/a/2950046/3716796">https://stackoverflow.com/a/2950046/3716796</a>  by Artefacto)
  <br>In short: 'PHP communicate[s] with the underlying file system as a <strong>"non-Unicode aware program"</strong>', and because of that all filenames given to PHP by Windows and vice versa are automatically translated/reencoded by Windows. This causes the errors. And you seemingly can't stop the automatic reencoding.<br>
  (And <a href="https://stackoverflow.com/a/2888039/3716796">https://stackoverflow.com/a/2888039/3716796</a>  by Artefacto: <br>"<strong>PHP does not use the wide WIN32 API</strong> calls, so you're limited by the codepage.")<br>
  And at <a href="https://bugs.php.net/bug.php?id=47096" rel="nofollow noreferrer">https://bugs.php.net/bug.php?id=47096</a>  there is the bug report for PHP.<br></p>
  
  <blockquote>
    <p><strong>Though on there nicolas suggests, that a COM-object might work!</strong> <br><strong>$fs = new COM('Scripting.FileSystemObject', null,
    CP_UTF8);</strong><br></p>
  </blockquote>
  
  <p>Maybe I will try that sometimes.<br><br>
  <strong><em>So there is the part of my questionleft : Is there PHP6 out, or was it withdrawn, or is there anything new on PHP about that topic?</em></strong></p>
  
  <p>// full Question<br>
  The most questions about this topic are 1 to 5 years old.
  Could php now save a file using
  file_put_contents($dir . '/' . $_POST['fileName'], $_POST['content']);</p>
  
  <p>when the $_POST['fileName'] is UTF-8 encoded, for example "Крым.xml" ?
  Currently it is saved as
  ÐšÑ€Ñ‹Ð¼.xml</p>
  
  <p>I checked the fileName variable, so I can be sure it's UTF-8:
  echo mb_detect_encoding($_POST['fileName']);</p>
  
  <ol>
  <li>Is there now anything new in PHP that could accomplish it?</li>
  <li>At some places I read PHP 6 would be able to do it, but PHP 6 if i I remember right, has been withdrawn. ?</li>
  <li>In Windows Explorer I can change the name of a file to "Крым.xml". As far as I have understood the old questions&amp;answers, it should be possible to use file_put_contents if the fileName-var is simply encoded to the encoding used by windows 7 and it's NTFS disc.
  There is even 3 old question with answers that claim to have succeeded:<br> <a href="https://stackoverflow.com/questions/7502685/php-file-handling-with-utf-8-special-characters">PHP File Handling with UTF-8 Special Characters</a>
  <br> <a href="https://stackoverflow.com/questions/6980068/how-to-convert-utf-16le-to-utf-8-in-php">Convert UTF-16LE to UTF-8 in php</a>
  <br> and <a href="https://stackoverflow.com/questions/6467501/php-how-to-create-unicode-filenames">PHP: How to create unicode filenames</a>
  <br><br>Overall and most approved answers say it is not possible. 
  I checked all suggested answers already myself, and none works.</li>
  <li>How to definitly and with absolute accuracy find out, in which encoding my Win 7 and Explorer saves the filename on my NTFS disc and with German language setting?
  As said: I can create a file "Крым.xml" in the Explorer.</li>
  </ol>
  
  <p>My conclusion: <br>
  1. Either file_put_contents doesn'T work correctly when handing over the fileName (which I tried with conversions to UTF-16, UTF-16LE, ISO-8859-1 and Windows-1252) to Windows, 
  <br>2. or file_put_contents just doesn't implement a way to call Windows' own file function in the appropriate way (so this second possibility would mean it's not a bug but just not implemented.) (For example notepad++ has no problems creating, writing and renaming a file called Крым.xml.)</p>
  
  <p>Just one example of the error messages I got, in this case when I used 
  mb_convert_encoding($theFilename , 'Windows-1252' , 'UTF-8')</p>
  
  <p>"Warning: file_put_contents(dirToSaveIn/????.xml): failed to open stream: No error in C:\aa xampp\htdocs\myinterface.lo\myinterface\phpWriteLocalSearchResponseXML.php on line 26 "
  With other conversion I got other error messages, ranging from 'invalid characters' to no string recognized at all.</p>
  
  <p>Greetings
  John  </p>