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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10623296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:38:45  来源:igfitidea点击:

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

phpcachingfopen

提问by Ben

Im using this tutorial http://papermashup.com/caching-dynamic-php-pages-easily/for caching a page

我使用本教程http://papermashup.com/caching-dynamic-php-pages-easily/缓存页面

<?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
}
?>

but i get the following errors

但我收到以下错误

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

The path to the file is right. And if i edit the file my self is included but again i get the errors

文件路径是对的。如果我编辑文件,我的自我被包含在内,但我再次收到错误

回答by DaveRandom

You have a problem with the casing of your variable name. PHP variable names are case sensitive. Change cacheFileto cachefile(with the small Finstead).

您的变量名的大小写有问题。PHP 变量名区分大小写。更改cacheFilecachefile(用小F代替)。

Change this:

改变这个:

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

To this:

对此:

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

回答by Michael Seibt

You got a spelling error: $cachefile!= $cacheFilePHP identifiers are case sensitive. So decide for one version and correct the other occurences.

您遇到拼写错误:$cachefile!= $cacheFilePHP 标识符区分大小写。所以决定一个版本并纠正其他出现的情况。

Corrected Code:

更正的代码:

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

回答by Brian Warshaw

The first time you reference $cachefile. The second time you reference $cacheFile. Fix the casing in one place or the other and you should be good.

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