1

I have a file c:/localweb/img/안녕.png

when I use,

$data = file_get_contents('c:/localweb/img/안녕.png');

I have a not found exception. I guess this is because there are korean chars. The files' names need to use korean characters though.

Is there a way to get the file's data ? converting the string or something ?

vdegenne
  • 12,272
  • 14
  • 80
  • 106

1 Answers1

1

On the PHP manual page they noted:

If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().

Maybe this will help you, so it's going to be:

$data = file_get_contents(urlencode('c:/localweb/img/안녕.png'));

Hope this will help you

D3F
  • 156
  • 1
  • 9
  • What has the manual quote to do with OP's problem? I don't see any spaces in OP's path?! – Rizier123 Apr 03 '15 at 20:44
  • Because of: URI with special characters – D3F Apr 03 '15 at 20:44
  • I saw many answers but I think urlencode() is the right choice for a direct measure-taking. However I think your example lack of logic, urlencode will encode all the characters of your string. urlencode() is no likely to work as the returned string is just intended to be used in a url printable environment. I am gonna use the function to generate a filename both usable in php and html environment. +1 because your answer headed me on a way but I don't yet accept it as it is semantically poor. – vdegenne Apr 03 '15 at 21:47
  • OK np, i was just hoping that my answer was pushing you in the right way. Did you figured it out? And would you share it here? – D3F Apr 03 '15 at 22:06
  • @D3F I can't, my question was selfishly refered as a duplicate. – vdegenne Apr 04 '15 at 08:07