|
Posted by Jim Moseby on 10/18/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]
|