title: How to store uploaded files with non-ASCII filename?
body: <p>I cannot pass a <strong>UTF-8</strong> filename to <a href="http://php.net/manual/function.move-uploaded-file.php" rel="nofollow"><code>move_uploaded_file()</code></a> as it gets converted bytewise, resulting in a faulty name in the file system. For example: </p>
  
  <pre><code>move_uploaded_file($_FILES['userfile']['tmp_name'], '\upload\é.jpg');
  </code></pre>
  
  <p>creates <em>xa9.jpg</em> in the upload directory.</p>
  
  <p>While the Windows API supports <strong>UTF-16</strong>, passing such filename (e.g., <a href="http://www.php.net/manual/function.iconv.php" rel="nofollow"><code>iconv('UTF-8', 'UTF-16', 'é')</code></a>) to <code>move_uploaded_file()</code> results in an error.</p>
  
  <p>It would be reasonable to <strong>percent-encode</strong> all special characters, and I definitely should do the same with the URIs, according to <a href="http://www.ietf.org/rfc/rfc3986.txt" rel="nofollow">RFC 3986</a>. But when I use percent-encoded URIs, Apache gives a 404 error, as it decodes the URL and can't find anything by that name.</p>
  
  <p>For example: <code>&lt;img src="/upload/%C3%A9.jpg" /&gt;</code> gives the Apache error:</p>
  
  <blockquote>
    <p>File does not exist: […]/upload/\xc3\xa9.jpg.</p>
  </blockquote>
  
  <p>What would be the proper solution? If I rename the file in Windows (<em>é.jpg</em>), the encoded HTML URI (<em>%C3%A9.jpg</em>) works as expected.</p>
  
  <hr>
  
  <p>Some info on the subject: <a href="http://www.rooftopsolutions.nl/blog/filesystem-encoding-and-php" rel="nofollow">http://www.rooftopsolutions.nl/blog/filesystem-encoding-and-php</a></p>