gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:43:51 26 4
gpt4 key购买 nike

我正在使用本教程 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
}
?>

但我得到以下错误

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

文件路径正确。如果我编辑文件,我自己也会被包含在内,但我再次收到错误

最佳答案

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

改变这个:

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

对此:

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

关于php - 警告 : fopen() [function. fopen]:文件名不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10623296/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com