You are here: RE: [PHP] Uploaded CSV -> database « PHP « IT news, forums, messages
RE: [PHP] Uploaded CSV -> database

Posted by Jim Moseby on 10/06/04 11:29

> -----Original Message-----
> From: Brian Dunning [mailto:brian@briandunning.com]
> Sent: Monday, October 17, 2005 11:39 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Uploaded CSV -> database
>
>
> It looks like all of those tips will easily cover me for the latter
> half of the operation. Any tips on how to get the uploaded CSV file
> into memory in order to attack it with fgetcsv()? I'd rather
> not ever
> have to actually write the file to the server's disk.
>
> Thanks!
>

If you are using the "standard" file upload facilities, your file is being
written to disk when it is being uploaded. As far as I can tell, fgetcsv()
will only read a file from disk:

<?php // from the manual
$row = 1;
$handle = fopen ("test.csv","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=0; $c < $num; $c++) {
print $data[$c] . "<br>\n";
}
}
fclose ($handle);
?>

If you are instead using a socket connection to receive the file in a stream
from the client, you could assign it to a string variable, and use
explode().

These are fairly uncharted territories for me, so others will likely have
better answers.

JM

 

Navigation:

[Reply to this 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

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