file_get_contents 无效

file_get_contents doesn't work

$z = file_get_contents("vars.txt");
var_dump($z);

这是我当前的代码。当我 运行 它时,我看到这个输出:

string(0) ""

我不确定为什么 - 此文件包含 321 个字符。它与我的 PHP 脚本位于同一目录中。你能解释一下原因吗,为什么那行不通?写入此文件工作正常(使用 "w+" 模式)。

虽然这是 chmod 错误,但我写了 chmod 777 dir 命令,但仍然不起作用。

我的脚本的完整代码在那里:https://gist.github.com/ty221/274bda4ecec03f710691

显示所有错误 E_ALL 不起作用 - 我的意思是什么都没有显示。

看看说明书怎么样:http://php.net/manual/en/function.fopen.php

引自那里:

'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
^^^^^^^^^^^

这意味着你的行:

//Deletes all content in the file
$file = fopen("vars.txt", "w+");

$to_save = "";

//Reads the content from a empty file
$z = file_get_contents("vars.txt");
//Outputs an empty string
var_dump($z);