RE: Uploaded CSV -> database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Brian Dunning [mailto:brian@xxxxxxxxxxxxxxxx]
> Sent: Monday, October 17, 2005 11:39 AM
> To: php-general@xxxxxxxxxxxxx
> Subject: Re:  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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux