|  | Posted by "Ben Litton" on 06/17/61 11:29 
Actually I think fgetcsv will work with any valid file pointer and at  least in PHP 5, the streams implementation will allow you to use a variety
 of protocols to create the stream.
 
 http://us2.php.net/manual/en/wrappers.php
 
 I understand that it isn't even too teribbly difficult to implement your
 own stream if one isn't already to your liking, but I'm afraid I haven't
 found need to go beyond the simple read-a-file-from disk style operation.
 
 Ben
 
 On Mon, 17 Oct 2005 11:45:04 -0400, Jim Moseby <JMoseby@nrbindustries.com>
 wrote:
 
 >> -----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
 
 
 
 --
 Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
  Navigation: [Reply to this message] |