SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need an expert to check this code

    Hello,

    I have some very important files that I have to update regularly. I used to do this in PERL but now I want to switch to PHP. I've created the following piece of code to open, lock, read, write and then close a file all at once. The code is as follows:

    PHP Code:
    $filename "veryimportantfile.irs";
    $file fopen($filename"r+");
    flock($file,2); 
    $text fread ($filefilesize ($filename));
    .....
    edit the input here.........
    rewind($file);
    ftruncate($file,0); 
    fwrite($file$text);
    fclose($file); 
    I've tested this code and it seems to be working fine. But I want someone else to take a look at it before I really start using it. The files that I want to update are very important so I can't afford to have a script that doesn't work properly or that will corrupt the files.

    Please take a look and tell me what you think.

    P.S. I don't want to read the file and then open it for writing, it MUST be done all at once. Can't explain any further but this is a must.

  2. #2
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Secrecy is the fuel for sceptical ppl...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"


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
  •