0

please help me!

I'm trying to create website with simple form. User will have an opportunity to send a photo via form. The problem is that when I'm trying to put image by using AJAX and PHP to pre-created folder, and to modify the name of file with gmdate() function it creates the file with unknown signs. Here is the example:

 <!DOCTYPE html>
     <html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     ...
     </head>
     ...
     <body>
        <form id="data" method="POST" action='' enctype="multipart/form-data">
        ...
          <input type="file" name="foto" id="foto" placeholder="Фотография" accept="image/*" required/>
        ...
     </body>

And here is my PHP file, that receives photo:

      header('Content-Type: text/html; charset=utf-8');
      ...
      move_uploaded_file($_FILES['foto']['tmp_name'], "img/". gmdate('H_i_s_', time()+3*3600) . $_FILES['foto']['name']);

But when I send the file with cyrillic name(for example 'я иду на работу.jpg'), it puts the wrong name ('16_54_31_СЏ РЅР° работуI.jpg'). I understand that the problem is related to encoding, but what should I do?? I checked by developers tool in browser, that name of file goes correctly to PHP

spacehaz
  • 61
  • 6
  • It will probably depend on the configuration of your server. To accomplish compatibility, try to use any way to avoid using special characters. I already had similar issues with Polish characters. – Liglo App Nov 17 '14 at 14:14
  • 3
    the page might be encoded in utf8 when it goes server->client, but if your FILESYSTEM is in some other charset, you'll get corrupted chars. the header() call before your move will not affect the move either. headers are information for the CLIENT, and do not affect anything happening on the server. – Marc B Nov 17 '14 at 14:14
  • also see http://stackoverflow.com/search?q=%5Bphp%5D+encoding+upload+filenames – deceze Nov 17 '14 at 14:17
  • Summary: it's extremely filesystem-specific how to handle non-ASCII filenames, and you'll need to take care of the conversion by hand. Often it's not worth the headache and it's better to not use user-supplied file names to begin with. Store the file under some randomly generated ASCII name. – deceze Nov 17 '14 at 14:19

0 Answers0