簡體   English   中英

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

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

我使用本教程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變量名稱區分大小寫。 更改cacheFilecachefile (與小F代替)。

改變這個:

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

對此:

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

您遇到拼寫錯誤: $cachefile != $cacheFile PHP標識符區分大小寫。 因此決定使用一個版本並更正其他版本。

更正代碼:

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

第一次引用$cachefile 第二次引用$cacheFile 將外殼固定在一個地方或另一個地方,你應該是好的。

對我來說是因為我對該文件的權限不足,所以我用chmod解決了它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM