file_put_contents() for PHP4

Simplified, but still...

<?php
if (!function_exists('file_put_contents')) {
    function file_put_contents($filename, $data) {
        $f = @fopen($filename, 'w');
        if (!$f) {
            return false;
        } else {
            $bytes = fwrite($f, $data);
            fclose($f);
            return $bytes;
        }
    }
}
?>

Bookmark and Share

Somewhat related posts

6 Responses to “file_put_contents() for PHP4”

  1. Adam Dempsey Says:

    Shouldn’t the title be file_put_contents?

  2. Stoyan Says:

    oops, thanks Adam!

  3. Sam Says:

    Thanks very much - a useful function!

  4. olivetalks » Blog Archive » Register_Globals Off and PHP4 Says:

    [...] a bit more research and I found out that the function which appears in the script from B&T’s Tips & Scripts: file_put_contents() works with PHP5 but not with PHP4 which is what I have. Some googling for “file_put_contents() for PHP4″ brings up quite a few implementations of the PHP5 file_put_contents() function for PHP4. The one I settled for can be found in Stoyan Stefanov’s blog phppied.com (thanks Stoyan!) [...]

  5. Surjit Says:

    thanks very much, it was very usefull for me

  6. Derek Says:

    (”Beginner”) Can you explain this a bit?

    If I have file_put_contents(”$archiveDir/$archiveFilename”, $output); how do I make it work using this?

Leave a Reply