dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: php > write to file top

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Posts
    110
    this *shouldn't* be very difficult.

    i am trying to make this code write data to the TOP of a *dat file...the way it is set up now it erases the archived file contents and overwrites it with the new data, but consequently gives this error:
    "Warning: stat failed for Resource id #1 (errno=2 - No such file or directory) in /usr/local/psa/home/vhosts/asoe.net/httpdocs/admin/twWriter.php on line 32"

    which again is the line containing:
    "$archivedContents = fread($file, filesize($file));"

    any help appreciated.

    cheers.
    +justin

    Code:
    function postDailyNews($sub_dailyNewsData) {
         
         $postDate = time();
         $postUser = JB;
         
         $file = fopen('dailyNews.dat', 'r');
         $archivedContents = fread($file, filesize($file));
         fclose($file);
    
         $file = fopen('dailyNews.dat', 'w');
         if (!$file) {
             fail("COULDNT OPEN FILE");
         }
         fwrite($file, "$postUser|$postDate|$sub_dailyNewsData\n$archivedContents");
         fclose($file);
    	
    	 success();
    	 return true;
    }

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    I think you should use
    filesize('dailyNews.dat')
    in your code. Check http://www.php.net/manual/en/function.filesize.php

    Musicman

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Posts
    110
    thanks musicman, that got it fixed nicely!

    cheers.

    +justin_____

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center