2012-05-16 46 views
1

进出口使用本教程http://papermashup.com/caching-dynamic-php-pages-easily/用于缓存页面警告:fopen()函数[function.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)) { 
    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 
} 
?> 

文件名不能为空,但我得到了以下错误

Warning: fopen() [function.fopen]: Filename cannot be empty in 

Warning: fwrite(): supplied argument is not a valid stream resource in 

Warning: fclose(): supplied argument is not a valid stream resource in 

路径到该文件是正确的。如果我编辑文件我的自我包括但我再次出现错误

+0

是什么'的var_dump()'ING的相关变量告诉你吗? –

+0

该文件的路径是什么?相对还是绝对? – ametren

回答

6

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

更改此:

要这样:

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

你有拼写错误:$cachefile!= $cacheFile PHP标识符区分大小写。因此,决定一个版本并纠正其他问题。

更正代码:

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

是的,这是错误的..谢谢 – Ben

3

您参考$cachefile第一次。你第二次参考$cacheFile。将套管固定在一个地方或另一个地方,你应该很好。