How do I load a text file to Database in PHP?

dc_music_fusion

New Member
Originally \[code\]$filepath\[/code\] is like this\[code\]$filepath=$_SERVER['DOCUMENT_ROOT']."/".SCRIPTFOLDER."somefile.txt";$sqlquerynew = "LOAD DATA INFILE '".$filepath."' INTO TABLE mytable FIELDS TERMINATED BY ','";mysql_query($sqlquery);\[/code\]That works. It sits on the server.But what if I want to put \[code\]somefile.txt\[/code\] outside the same server? If I put that in dropbox, and reuse the code like the following, it doesn't do anything.\[code\]$sqlquerycreate = / ** Here insert DB scheme code **/$filepath="http://example.com/somefile.txt";$sqlquerynew = "LOAD DATA INFILE '".$filepath."' INTO TABLE mytable FIELDS TERMINATED BY ','";mysql_query($sqlquery);\[/code\]What should I do instead? The text file contains the data for the table.Thanks.\[code\]$data_file = file_get_contents('http://dl.dropbox.com/u/14655573/john/nyccrash.txt');file_put_contents('C:\xampp\htdocs\import\nyccrash.txt', $data_file);$filepath = "C:\xampp\htdocs\import\nyccrash.txt";echo $filepath;$sqlquery = "LOAD DATA INFILE '".$filepath."' INTO TABLE nyccrash FIELDS TERMINATED BY ',' (crash_year, accident_type, collision_type,weather_condition,light_condition,x_coordinate,y_coordinate)";\[/code\]Okay. I see this file now. But it didn't get import to the DB. This is XAMPP. But I will, eventually, move to Ubuntu. What's the problem with this code?
 
Top