У меня есть проблема при попытке открыть файл и просмотреть его содержимое с помощью PHPКак открыть файл и отобразить его содержимое с помощью php?
Мой файл называется hello.txt
Вот мой PHP код
<?php
$filename = 'hello.txt';
$filePath = 'c:\\Users\\bheng\\Desktop\\'.$filename;
if(file_exists($filePath)) {
echo "File Found.";
$handle = fopen($filePath, "rb");
$fileContents = fread($handle, filesize($filePath));
fclose($handle);
if(!empty($fileContents)) {
echo "<pre>".$fileContents."</pre>";
}
}
else {
echo "File Not Found.";
}
?>
Я получил это от http://php.net/manual/en/function.fread.php
Я продолжаю получать ошибку:
fread(): Length parameter must be greater than 0
Может кто-нибудь помочь мне, пожалуйста?
Попробуйте file_get_contents упростить вещи – JAL
$ имя_файла = 'Hello php.txt'; OR $ filename = 'hello.txt'; ??? – andrew
@andrew: Извините. Это опечатка. Я починил это. – iori