Page 1 of 1

read a file from a specific address

Posted: Sun Apr 25, 2010 1:16 pm
by minasaeedi
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:

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);
                       
		}
	}
}
Please help me if you have experience.Thank you

Re: read a file from a specific address

Posted: Sun Apr 25, 2010 3:09 pm
by requinix
PHP can't read a file on your machine. You have to upload it.

Re: read a file from a specific address

Posted: Mon Apr 26, 2010 5:43 am
by minasaeedi
Ok,

so how can I upload it automatically ? I want the file to be uploaded when I click on a button and the read from file process will start after automatically upload the file and read the contents from file and update database....

thank you

Re: read a file from a specific address

Posted: Mon Apr 26, 2010 12:10 pm
by Jonah Bron
Is this something that can be uploaded once? If so, then just put it up the same way you uploaded your PHP to the server: probably with FTP.

If this is a file that introduces new information every time uploaded, then you will need to take a look at this

http://google.com/search?q=php+uploading