dre93205 2016-01-14 23:50
浏览 207
已采纳

从PHP中的文本文件中读取[重复]

I am using this code to try and read the values in a text file.

$mapFile = fopen('config/map.txt', 'r') or die ("Can't open config file");
while ($line = fread($mapfile,filesize('config/map.txt')))
{
    echo $line;
}

Instead I keep getting this error.

Warning: fread() expects parameter 1 to be resource, null given

I am unsure what I am doing wrong. How can I read the text in the file properly?

</div>
  • 写回答

3条回答 默认 最新

  • dongyanpai2701 2016-01-14 23:53
    关注

    PHP variables are case sensitive. $mapFile !== $mapfile.

    $mapFile = fopen('config/map.txt', 'r'); // don't need `or die()`
    while ($line = fread($mapFile, filesize('config/map.txt')))
    {
        echo $line;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?