3
votes

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
Please have a look at stackoverflow.com/questions/10008341/…Apb
That character is a bit problematic, there are issues converting it between Unicode and SJIS, see also stackoverflow.com/questions/34894581/…Thilo
Use var_dump(is_file("c:\\\\表\\t.txt"), is_readable("c:\\\\表\\t.txt")); to debug.The Onin

4 Answers

2
votes

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.

1
votes

try this

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

echo $con;
?>
1
votes

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.

0
votes

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