3

This code get content file txt:

$str = "c:\\\\表\\t.txt"; $con=file_get_contents( $str); echo $con; 

File exist in folder:

enter image description here

Result: show error:

Warning: file_get_contents(c:\表\t.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 6

Why is file_get_contents() not working?

How read content of path c:\表\t.txt?

4

4 Answers 4

2

Try to use urlencode to encode your directory name:

$str = 'c:\\'.urlencode('表').'\t.txt'; $con=file_get_contents( $str); echo $con; 

This is described here in detail.

EDIT

Assuming you're using UTF-8 encoded source files, you could also try one of the following

$str = 'c:\\'.urlencode(mb_convert_encoding('表', 'UTF-16', 'UTF-8')).'\t.txt'; // or just $str = 'c:\\'.mb_convert_encoding('表', 'UTF-16', 'UTF-8').'\t.txt'; 

As far as I know newer (> FAT32) Microsoft filesystems use UTF-16 encoding. But this will make your solution fail on other (e.g. Linux) filesystems.

EDIT 2

You can also try to convert your UTF-8 filename into a different encoding such as SJIS, SJIS-win, SJIS-2004, JIS, EUC-JP, eucJP-win, EUC-JP-2004, CP932, JIS-ms or the like. But I'm not an expert in east asian character encodings - so treat that information with caution.

Sign up to request clarification or add additional context in comments.

5 Comments

Warning: file_get_contents(c:\%E8%A1%A8\t.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 6
What's the character encoding of your file? UTF-8?
my file is utf-8, it still show errror: Warning: : failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 6
i try change UTF-16 to all encode: SJIS, SJIS-win, SJIS-2004, JIS, EUC-JP, eucJP-win, EUC-JP-2004, CP932, JIS-ms, but it still not woking.
@DT: Then I think you're out of look. If it's an option to change the name of the folder something containing only ASCII characters, the do this and you're done.
1

try this

<?PHP $con=file_get_contents('./表/t.txt', true); $con=file_get_contents('./表/t.txt',FILE_USE_INCLUDE_PATH); echo $con; ?> 

7 Comments

Warning: file_get_contents(C:/表/t.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 4
Warning: file_get_contents(./表/t.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 4 Warning: file_get_contents(./表/t.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 5
what is your corrent directory??
you just try this var_dump(getcwd());
this my folder "C:\表"
|
1

Language : PHP

$results = scandir('c:\'); $result will give you all folder name inside c drive. you can find your folder in $result array. now you have folder name in $result and now you can go to file. 

Modified :

$results = scandir('/web'); $results = "/web/$results[21]/t.txt"; $con=file_get_contents( $results); echo $con; 

Explanation :

1.) /web is the directory where is 表 folder and some other folders. 2.) $result[21] is giving me value 表 on browser i know its 表 folder. 3.) Now you have file path. Go ahead. 

NOTE : If you still use Chinese character in your folder and file then you have to change your OS from window to ubuntu.

9 Comments

result return folder 表 is string(2) "�\"
If you getting folder name in $result[2] then use it in your way. $str = "C:\$results[2]\.t.txt"; $con=file_get_contents( $str); echo $con;
it sill show error : Warning: : failed to open stream: No such file or directory in
do one thing. move your file in different drive or make a copy of that file and give permission to that file and apply your approach
Please come in chat. i will explain you there. I have ubuntu OS
|
0

Create path based on single /

$content = file_get_contents("C:/表/t.txt"); 

You can read more about Filesystem here: http://php.net/manual/en/wrappers.file.php

2 Comments

Warning: file_get_contents(c:/表/t.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 3
Warning: file_get_contents(C%3A%2F%E8%A1%A8%2Ft.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\direction\test.php on line 4

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.