read a file from a specific address
Posted: Sun Apr 25, 2010 1:16 pm
Hello ,
Can someone please help me to correct this code :
This is a application running on server host , reading some lines from a txt file and updates the database.
Until now, I had to put the file on server in a specific folder, but I want to change the code so I don't have to upload the txt file to the server application folder,let the application read file contents from my local desktop or partition location:
Please help me if you have experience.Thank you
This is a application running on server host , reading some lines from a txt file and updates the database.
Until now, I had to put the file on server in a specific folder, but I want to change the code so I don't have to upload the txt file to the server application folder,let the application read file contents from my local desktop or partition location:
Code: Select all
function create_tables_from_files (){
global $tables;
$current_directory=getcwd();
$current_directory = str_replace('\\','/',$current_directory);
foreach ($tables as $k => $tablename){
drop_table('temp.'.$tablename);
$q="CREATE TABLE temp.{$tablename}
(id CHAR(36) NOT NULL PRIMARY KEY,name TEXT NOT NULL, lastname TEXT NOT NULL);";
execute_query($q);
// I have to correct this line , tell the code to read not from current directory/temp but from my localcomputer Desktop for example...
$q= "LOAD DATA LOCAL INFILE '{$current_directory}/temp/{$tablename}.txt' INTO TABLE temp.{$tablename} LINES TERMINATED BY '\n';";
execute_query($q);
$q = "SELECT t.id, name FROM temp.{$tablename} t";
$r= execute_query($q);
while ($row = mysql_fetch_row($r)) {
$q="UPDATE temp.{$tablename} t SET t.name= '{$row[1]}',t. lastname='{$row[2]}' WHERE t.id = '{$row[0]}';";
execute_query($q);
}
}
}