Results 1 to 4 of 4
  1. #1

    txt file into mysql with php

    I have a client whose system continously uploads to a directory on a webserver a txt file with the data of a table that needs to be fed every day with sales reports for each day so that the txt file is updated, (that is the txt file it's replaced dayly for its new version, keeping the same name for the txt file) hence, the txt file changes every day, but the info of previous days must be kept on a mysql data base, having the information for each day whilst the txt file only has the info for one particular instance, for the particular day we be on, so the information of the rest of the previous days will not be at the txt file but will be saved at the mysql data
    how do I do this who is the genious who can tell me this??????


    I have this idea: the txt file is: "report.txt", the table is "tablereports", the phpfile name is: "solution.php", which has this code :


    <?

    // we conect to our data base (say reportsdb) and all that (I know how to do this,
    //I guess) , then we do this:

    $sql = "LOAD DATA LOCAL INFILE report.txt INTO TABLE tablereports"


    //or is it:


    //$sql = "LOAD DATA LOCAL INFILE "report.txt" INTO TABLE tablereports"

    //???????



    //then I add code to show results and all that (I know how to do this, I guess)

    >

    is this correct?
    do I have to add the path to the file before the name, if the php file,"solution.php", and the txt file, "report.txt", are in the same directories?



    and, then to always have the table updated:

    HOW CAN I RUN THE SCRIPT LIKE SAY ONCE EVERY DAY OR ONCE EVERY DAY, WITH OUT HAVING THE CLIENT RUNNING "solutions.php" ,
    SO I CAN UPDATE the table AUTOMATICALLY every day?





    .
    .
    .
    .
    .

    .
    .
    .
    Last edited by healthy; 04-06-2008 at 08:38 PM.

  2. #2
    Join Date
    Mar 2006
    Posts
    965
    Is your report.txt file information fetched or needs to be fetched after each uploads before adding the infos into the database ?

  3. #3
    they write the information in the txt file every day
    (deleting the info of the previous day)
    I have to insert it into a mysql db

    by the way would it be better to use the function:
    "file()"

    and then make an "insert into" with "values" for each row

    and isnt it dangerous, I mean the txt file can be seen on line if the path is found, or is there a way to protect it?

  4. #4
    Join Date
    Mar 2006
    Posts
    965
    and isnt it dangerous, I mean the txt file can be seen on line if the path is found, or is there a way to protect it?
    That is the point of my question and yes there's a way to protect it. A quick way to accomplish this would be by fetching each lines the user has entered into his TXT file (like a CSV file format) and use the list function to separate each contents in order to store them properly into mySQL. Once all the content are injected in the database, it would be safe to instantly delete the uploaded TXT file from the server by using the unlink function (and need to set the proper CHMOD settings from FTP / cPanel in order for the server to accept all deleting process from the source).

    Note: Use mysql_real_escape_string for arrays, mysql_escape_string for non-arrays or PDO for SQL injection.

Posting Permissions

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