SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Next Door
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    question, save_file function with fwrite

    Hi, I have a script here downloaded from the net. It works fine, I'm just not quite clear how it works.
    Code:
    function save_file($filename, $contents) {
        $i = 0;
        do {
            $handle = fopen($filename, "w+");
            $fout = fwrite($handle, $contents);
            fclose($handle);
            $i++;
        } while(filesize($filename) < 5 && $i < 5);
    }
    Can someone please explain the while() part? Why does it need a loop to save files? and what is the $i for?

    any information would be greatly appreciated.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    It seems like the function is used to make sure that the size of the file is at least five bytes. What it does is to write $content to the specified file as long as the filesize is less than five bytes. It will not write $content to the file more than five times. Personally, I think that the function is of no use unless you want to make sure that the size of the file exceeds five bytes.

    Yours, Erik.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •