0

Here is my code which is not saving image filename in utf8 format in php,

header('Content-type: text/html; charset=utf-8');
$data = $_POST ['img'];
$data = str_replace ( 'data:image/png;base64,', '', $data );
$data = base64_decode ( $data );
$meme_filename_in_utf8  = "UTF8 STRING NAME";
$url = UPLOAD_DIR . $meme_filename_in_utf8 . '.jpg';
$source_url = imagecreatefromstring($data);
imagejpeg($source_url, $url, 90);

The above code saves image using imagejpeg, but file name is saving as "இநà¯Âத-மாஸà¯Â.jpg". I need to save image in utf8 format.

  • How should the file name actually look like? – lenz Jan 29 '18 at 08:56
  • What character encoding was this script files saved in? – CBroe Jan 29 '18 at 08:57
  • File name actually looks in tamil language it will be in utf8_general_ci @lenz – Gowthamraj Somanathan Jan 29 '18 at 09:04
  • Can you show the file name, please? – lenz Jan 29 '18 at 09:05
  • File name should be "இந்த மாஸ்டர் என்ன.jpg" but it is looks like à ®‡à ®¨à ¯Âà ®¤-à ®®à ®¾à ®¸à ¯Â.jpg @lenz – Gowthamraj Somanathan Jan 29 '18 at 09:07
  • 1
    In a nutshell: it's somewhere between a giant headache and impossible to create specific non-ASCII filenames and you probably don't want to bother with it. – deceze Jan 29 '18 at 09:10
  • To me it looks like the file name actually *was* encoded with UTF-8, but the OS is interpreting it with a different codec. I couldn't figure out what codec that would be, though. And deceze is right – it might not be worth the pain. – lenz Jan 29 '18 at 09:19

0 Answers0