Reply to Re: [PHP] Uploaded CSV -> database

Your name:

Reply:


Posted by Brian Dunning on 10/18/05 16:15

Amazing - it works! The uploaded file is always stored in the temp
directory, so that issue was kind of moot. Here's my complete code,
if anyone else has this same need:

if(isset($_FILES['userfile']['tmp_name'])) {
$csvfile = fopen($_FILES['userfile']['tmp_name'], "r");
if($csvfile == FALSE) die('error opening file');
while(($datarow = fgetcsv($csvfile, 1000)) !== FALSE) {
$name = isset($datarow[0]) ? $datarow[0] : '';
$addr = isset($datarow[1]) ? $datarow[1] : '';
$city = isset($datarow[4]) ? $datarow[4] : '';
$state = isset($datarow[5]) ? $datarow[5] : '';
$zip = isset($datarow[6]) ? $datarow[6] : '';
$query = "insert into dealers
(account_id,name,addr,city,state) values
('$account_id','$name','$addr','$city','$state','$zip');";
$result = mysql_query($query) or die(mysql_error());
}
fclose($csvfile);
}

I was really surprised at how short & simple this turned out to be.
There is plenty of room for error-checking in the above snippet, but
what's there works when there are no problems.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация