Php 警告:fopen()[function.fopen]:文件名在中不能为空

Php 警告:fopen()[function.fopen]:文件名在中不能为空,php,caching,fopen,Php,Caching,Fopen,我正在使用本教程缓存页面 <?php { $cachefile = $_SERVER['DOCUMENT_ROOT'].'cache.html'; $cachetime = 4 * 60; // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { in

我正在使用本教程缓存页面

<?php {
$cachefile = $_SERVER['DOCUMENT_ROOT'].'cache.html';
$cachetime = 4 * 60;
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
    include($cachefile);
} else {
ob_start(); // Start the output buffer
 ?>

/* Heres where you put your page content */


<?php 
// Cache the contents to a file
$cached = fopen($cacheFile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser
}
?>

文件的路径是正确的。如果我编辑了这个文件,我自己也会被包括在内,但我还是得到了错误,你得到了一个拼写错误:
$cachefile
!=
$cacheFile
PHP标识符区分大小写。因此,决定一个版本,并纠正其他出现的问题

更正代码:

$cached = fopen($cachefile, 'w');

第一次引用
$cachefile
。第二次引用
$cacheFile
。将大小写固定在一个位置或另一个位置,您应该很好。

您的变量名大小写有问题。PHP变量名区分大小写。将
cacheFile
更改为
cacheFile
(改为使用小的F

更改此项:

$cached = fopen($cacheFile, 'w');
为此:

$cached = fopen($cachefile, 'w');

var\u dump()
ing相关变量告诉您什么?文件的路径是什么?它是相对的还是绝对的?
$cached = fopen($cachefile, 'w');