read a file from a specific address

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
minasaeedi
Forum Newbie
Posts: 6
Joined: Sat Jan 16, 2010 2:39 am

read a file from a specific address

Post 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
Last edited by Benjamin on Sun Apr 25, 2010 1:34 pm, edited 1 time in total.
Reason: Added [syntax=sql] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: read a file from a specific address

Post by requinix »

PHP can't read a file on your machine. You have to upload it.
minasaeedi
Forum Newbie
Posts: 6
Joined: Sat Jan 16, 2010 2:39 am

Re: read a file from a specific address

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: read a file from a specific address

Post 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
Post Reply