OK, I want to write a script that will allow someone to upload a txt file to a MySQL database.

The guy will login, got to the upload page where there is a form with a file input field. Simple enough, right.

The MySQL query var should look like this:

$sql = 'LOAD DATA INFILE \'c:\\php\\uploadtemp\\php1.tmp\' REPLACE INTO TABLE table_name ';
$sql .= 'FIELDS TERMINATED BY \',\'';
$sql .= 'OPTIONALLY ENCLOSED BY \'"\'';
$sql .= 'ESCAPED BY \'\\\'';
$sql .= 'LINES TERMINATED BY \'\r\n\'';

My problem lies in the file that will be uploaded. It will go to the uploadtemp directory, but what happens to it after that is a mystery to me.

I had a look at some phpMyAdmin code and found the two files that does the process in phpMyAdmin (Idi_table.php & Idi_check.php), but me being a bit of a noob at php, the files did not make a whole lot of sense.

Can someone help me with this, please?

    Thanx Natty_Dreadlock. 🙂
    The thing that actually threw me was that in phpMyAdmin the upload facility rename the file to .tmp and this is not the .txt filename I used.

    But I spoke to my ISP and the admin created a upload directory for me. So now I can Upload and do the MySQL query from that path.

      Write a Reply...