Garrett Posted October 15, 2009 Share Posted October 15, 2009 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 More sharing options...
waynew Posted October 15, 2009 Share Posted October 15, 2009 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(); Link to comment https://forums.phpfreaks.com/topic/177842-fwrite-troubles-caching/#findComment-937728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.