Jump to content

fwrite() troubles (caching)


Garrett

Recommended Posts

I am adding caching to my website and when writing to the file using fwrite I am getting:

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

 

My folder/file permissions for the target folder and the file running the php script is 755.

 

This is my code:

$cache_file = "cache/header.html";
if (file_exists($cachefile)) {
include($cachefile); 
exit;
}
ob_start();
...
...
$fp = fopen($cachefile, 'w'); 
fwrite($fp, ob_get_contents());
fclose($fp); 
ob_end_flush();

 

Any help would be great.

Link to comment
https://forums.phpfreaks.com/topic/177842-fwrite-troubles-caching/
Share on other sites

Whoops, you silly person!

 

//You put an underscore between cache and file
//whereas you're trying to use a variable called
//$cachefile that hasn't been set
$cache_file = "cache/header.html";
if (file_exists($cachefile)) {
   include($cachefile);
   exit;
}
ob_start();
...
...
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_flush();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.