Re: insert *.TAB into table

From: Date: Wed, 02 Aug 2000 08:08:50 +0000
Subject: Re: insert *.TAB into table
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-9643@lists.php.net to get a copy of this message
Hai, I read the part about fgets and put this script together when I put $fd = fopen ("test.tab","r"); it will work perfect. The problem is when I want to get an variable tab file trough an form setting an userfile he get the next error ; Warning: fopen("","r") - No such file or directory in /www/test/submit.php3 on line 8 Warning: Unable to find file identifier 0 in /www/test/submit.php3 on line 9 Warning: Unable to find file identifier 0 in /www/test/submit.php3 on line 36 #SCRIPT <? $fd = fopen ("$userfile","r"); while (!feof($fd)) { $buffer = fgets($fd, 4096); echo $buffer; if(preg_match("/(\d+)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)/i", $buffer, $parts)){ echo "id: $parts[1]<BR>"; echo "date: $parts[2]<BR>"; echo "title: $parts[3]<BR>"; echo "description: $parts[4]<BR><BR>"; $Query = "SELECT id FROM news WHERE id = $parts[1]"; $result = mysql_exec($Query); if(mysql_num_rows($result) > 0){ $Query = "UPDATE news SET id = $parts[1], date = '$parts[2]', title='$parts[3]', description='$parts[4]' WHERE id = $parts[1]"; mysql_exec($Query); }else{ $Query = "INSERT INTO nieuws (id,date,title,description) VALUES ($parts[1],'$parts[2]','$parts[3]','$parts[4]')"; mysql_exec($Query); } mysql_free_result($result); } } fclose($fd); ?> Sylwester Zarêbski <sylwek@isp.net.pl> schreef in berichtnieuws 3986D2CD.C226B9D7@isp.net.pl... > Vadee Prudon wrote: > > > > Hai, > > > > I'm using an *.tab file and importing like ; > > > > $fp = fopen ("$userfile","r"); > > while ($data = fgetcsv($fp, 10000, " ")){ > > > > $num = count($data); > > $row++; > > echo "<TR>"; > > for ($c=0; $c<$num; $c++){ > > echo "<TD>$data[$c]</TD>"; > > } > > echo "</TR>"; > > From php page comments: > "fgetcsv() seems to ignore zero-length fields when working > with tabs as separators (3.0.12). Instead work around this > with fgets() and do an explode() afterwards, this gets you > the right thing." > > -- > pozdrawiam.. > > ## ## | Sylwester Zarêbski - ISP Group | > #### ## | e-mail: sylwek@isp.net.pl | > ## ## ## | ICQ uin: #45780888 | > ## #### ## | Administrator ISP.NET.PL | > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#9643) next »