Filesize inconsistant

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Filesize inconsistant

    Not sure whether this is something Im doing wrong or just something
    the filesize() function doesnt support but...

    <?
    $fsize1 = filesize("foo.t xt");
    $fp = fopen("foo.txt" ,a);
    $time = time();
    fputs($fp,$time );
    fclose($fp);
    $fsize2 = filesize("foo.t xt");
    echo $fsize1." ".$fsize2;
    ?>

    this code always reports the $fsize1 equal to $fsize2 when surely they
    should be different?
  • Daniel Tryba

    #2
    Re: Filesize inconsistant

    David <biffta@hotmail .com> wrote:[color=blue]
    > this code always reports the $fsize1 equal to $fsize2 when surely they
    > should be different?[/color]

    This is a clear RTFM:

    "Note: The results of this function are cached."

    Comment

    • Kristian Köhntopp

      #3
      Re: Filesize inconsistant

      David wrote:[color=blue]
      > $fp = fopen("foo.txt" ,a);[/color]

      You mean "a", not a.
      [color=blue]
      > this code always reports the $fsize1 equal to $fsize2 when surely they
      > should be different?[/color]

      http://php.net/clearstatcache is your friend.

      Kristian

      Comment

      • David

        #4
        Re: Filesize inconsistant

        > This is a clear RTFM:

        Yeh thanks. Just in case anyone cares you can achieve what I wanted
        like this as well:

        $fp = fopen($filename ,"r");
        fseek($fp, 0, SEEK_END);
        $filesize1 = ftell($fp);
        fclose($fp);

        $time = time();
        $fp = fopen($filename ,"w");
        fputs($fp, $time);
        fclose($fp);

        $fp = fopen($filename ,"r");
        fseek($fp, 0, SEEK_END);
        $filesize2 = ftell($fp);
        fclose($fp);

        Comment

        • Daniel Tryba

          #5
          Re: Filesize inconsistant

          David <biffta@hotmail .com> wrote:[color=blue]
          > Yeh thanks. Just in case anyone cares you can achieve what I wanted
          > like this as well:
          >
          > $fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize1 = ftell($fp);
          > fclose($fp);[/color]
          [color=blue]
          > $time = time(); $fp = fopen($filename ,"w"); fputs($fp, $time); fclose($fp);[/color]
          [color=blue]
          > $fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize2 = ftell($fp);
          > fclose($fp);[/color]

          But that will always return the same filesize ("w" truncates file)
          (unless you happend to to sumble upon a switch from x to x+ digits (last
          time that happend was in 2001 IIRC, and will not happen for some time
          :))

          Comment

          • hopkins

            #6
            Re: Filesize inconsistant

            It will work, but only the first time you run it. If you replace $time
            with data of varying length (as is the case for me) it will always
            give different sizes.


            David <biffta@hotmail .com> wrote:[color=blue]
            > Yeh thanks. Just in case anyone cares you can achieve what I wanted
            > like this as well:
            >
            > $fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize1 = ftell($fp);
            > fclose($fp);
            > $time = time(); $fp = fopen($filename ,"w"); fputs($fp, $time); fclose($fp);
            > $fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize2 = ftell($fp);
            > fclose($fp);[/color]

            But that will always return the same filesize ("w" truncates file)
            (unless you happend to to sumble upon a switch from x to x+ digits
            (last
            time that happend was in 2001 IIRC, and will not happen for some time
            :))

            Comment

            Working...