AKor
AKor

Reputation: 8892

PHP file writing problem

I'm trying to write to a file in PHP to cache the output of a small portion of code.

        ob_start();
        echo "Hello";
     $fp = fopen("cache/ttcache.php", 'w');
        fwrite($fp, ob_get_contents());
        fclose($fp);
        ob_end_flush();

The file exists and is blank. The fwrite function points to the correct location. It just doesn't write.

Any help?

Upvotes: 0

Views: 521

Answers (2)

Rikesh
Rikesh

Reputation: 26451

Try to write first small word or sentence first.

fwrite($fp, 'hello')

Also check your file permission's should be writable.

Upvotes: 2

KingCrunch
KingCrunch

Reputation: 132061

Make sure ob_get_contents() is really not empty. Then try

fflush($fp);

right before fclose().

Upvotes: 0

Related Questions