Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Updating a file

  • 29-04-2010 09:04PM
    #1
    Registered Users, Registered Users 2 Posts: 7


    Hi there, i'm presently doing a project which requires a file to be updated by another file of same format.

    The operating system I'm using is windows and the project is a php based webpage. I need to update a file every xx mins and store it in my database.

    I'm not sure how to approach this, anybody have any suggestions??

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭Freddio


    the following code will overwrite

    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "Floppy Jalopy\n";
    fwrite($fh, $stringData);
    fclose($fh);


    the following code will continue adding everytime its run

    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    $stringData = "Floppy Jalopy\n";
    fwrite($fh, $stringData);
    fclose($fh);

    updating the database would depend on your schema (structure) but once you have established the connection to the database on the web page you can then send update statements using mysql_query()

    php.net is the bible for this stuff

    because your using a windows machine you will have to call the php script on a scheduler but if the script is available on the net you could call it up periodically from any other machine that's permanently on if you have limited web hosting


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    I guess this file is been updated by some other application.

    You could schedule a script to execute every xx minutes, that takes in the file to read and then updates the database based on the contents. In Linux, you could use cron but on windows you could use scheduled tasks to run php.exe to execute a script periodically.


Advertisement