0
<?php
$str='表/test.zip';
$str = mb_convert_encoding($str,"SJIS−win","UTF−8");
readfile(str);
?>

I got error with character 表. Error message is:

Warning: readfile(•\/test.zip): failed to open stream: No such file or directory in check.php on line 22 •\/test.zip

Of course 表/test.zip had already existed. I tried with other character except for text 表, all were OK, did NOT have any error.

Does anyone have any solution? Thank you very much for your help.

Note: It is not error about name of file, but error about name of path, name of folder is in JP. It is difference with php readdir problem with japanese language file name

Community
  • 1
  • 1
TinDoan
  • 21
  • 2
  • What is the file encoding of the php script? It needs to be UTF-8 without BOM. – Charlotte Dunois Jan 20 '16 at 08:07
  • That character shows up in a list of "bad" SJIS characters: https://sites.google.com/site/fudist/Home/grep/sjis-damemoji-jp I suppose it cannot be properly converted. – Thilo Jan 20 '16 at 08:08
  • If the file is stored in UTF-8, then you shouldn't need to convert `str`. – GolezTrol Jan 20 '16 at 08:13
  • is the `$str` variable coming from an SJIS source in the original code? If not, why are you converting the string from SJIS to UTF-8? – Jeemusu Jan 20 '16 at 08:14
  • `str` should be `$str`. And `′表/test.zip′` should be `'表/test.zip'`. Can you see the difference? paste it to your text editor. – choz Jan 20 '16 at 08:14
  • @Jeemusu `str` not `$str`. I wonder if str without `$` is possible in lower version of php. – jameshwart lopez Jan 20 '16 at 08:15
  • @jameshwartlopez Not that I can recall, I just assumed OP had mis-typed it when adding the code to the question. – Jeemusu Jan 20 '16 at 08:17
  • 1
    Using a relative path may be the problem. Try to access the file from an absolute path (eg `/home/me/表/test.zip`). If you cannot get it to work, do a link of the `表` dir to something *romaji*, something like `ln -s 表 uwabe`. Then in php access `uwabe/test.zip`. – Déjà vu Jan 20 '16 at 08:20
  • @Thilo: Your comment is the best, you saved my time. Thank you very much. Because it is in this black list. Thank you – TinDoan Jan 20 '16 at 08:21
  • 1
    @TinDoan Blacklisted or not, it's binary in a given encoding. So if your OS and file system can access it, the "blacklisting" may not be the problem. When accessing a letter in a given encoding, the system will not check if that gives a particular "blacklisted" character... See my other comment above. – Déjà vu Jan 20 '16 at 08:23

0 Answers0