Jump to content

fgetcsv oddity


SteveDoig

Recommended Posts

If I run the following code:

 

<?php
$row = 1;
$fp = fopen ("images.csv","r");
while ($data = fgetcsv ($fp, 20, ",")) {
   echo $data;
   $row++;
}
?>

 

I get the following output:

 

ArrayArrayArrayArrayArrayArrayArrayArray etc

 

 

In the images.csv file is a list of jpg filenames, with filenames no longer than 9 characters long, meaning the total row length is no longer than 13 characters.  eg.

 

123456.jpg

P1234567.jpg

 

Why is the CSV file not being read properly?

Link to comment
https://forums.phpfreaks.com/topic/103817-fgetcsv-oddity/
Share on other sites

Its is being read properly. PHP.NET tells you that the returned valued is

an indexed array containing the fields read.

 

<?php
$row = 1;
$fp = fopen ("images.csv","r");
while ($data = fgetcsv ($fp, 20, ",")) {
   for($i=0; $i<count($data); $i++){
       echo $data[$i];
   }
   $row++;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/103817-fgetcsv-oddity/#findComment-531515
Share on other sites

Okay thanks. 

 

I want to download some remote images onto my own remote server.

 

<?php
$row = 1;
$fp = fopen ("images.csv","r");
while ($data = fgetcsv ($fp, 20, ",")) {
       $BLA = 'http://www.bla.com.au/images/ProductGroup/' . $data[1];
       $download = '/home/hi/hil/hillarysboatshop.com.au/public/www/images/downloads/' . $data[1];
   	   if (!copy($BLA, $download)) {
     echo "failed to copy $BLA...\n";
   }
   $row++;
}

 

This is timing out.  Can you suggest a better method?

Link to comment
https://forums.phpfreaks.com/topic/103817-fgetcsv-oddity/#findComment-531536
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.