为什么可以';我看不到这个php脚本中的.txt文件

为什么可以';我看不到这个php脚本中的.txt文件,php,Php,我正在使用此脚本查看.text文件的内容- <?php $file = fopen("Gin_List_Website.txt","r"); if(!file) { echo("ERROR:cant open file .. :("); } else { echo("opened the file .. :)"); $buff = fread ($file,filesize("Gin_List_Website.txt")); print $buff;

我正在使用此脚本查看.text文件的内容-

<?php

$file = fopen("Gin_List_Website.txt","r");

if(!file)
{
    echo("ERROR:cant open file .. :(");
}
else
{
    echo("opened the file .. :)");

    $buff = fread ($file,filesize("Gin_List_Website.txt"));
    print $buff;
    echo $buff;
}
?> 

但我看到的只是这条线

已打开文件:)


我做错了什么?

首先,您需要将if(!file)更改为if(!$file)

下面是更简单的代码示例:

<?php
    $file = fopen("Gin_list_Website.txt", "r") or die("Unable to open file!");
    echo fread($file,filesize("Gin_list_Website.txt"));
    fclose($file);
?>


如果你只是想要完整的文件,为什么不使用
文件
文件获取内容
?将If(!file)更改为If(!$file)@bharatparmar我错过了,现在它给出了错误。你能显示错误吗?对不起,我的意思是“错误:无法打开文件…”在.php脚本中,我的php文件与我的.text文件位于同一目录下。我收到“无法打开文件!”错误,我的php文件与我的.text文件位于同一目录下。您是否对“Gin\u List\u Website.txt”设置了正确的权限文件?你的文本文件名和扩展名是什么?这是指向.txt文件的路径。你的文件名有问题。你的php代码中有大写字母“L”,而真实的文件名有小写字母“L”。我更新了答案代码,你可以试试。