Jump to content

[SOLVED] get CSV/GZIP file


iceblox

Recommended Posts

Hi All,

 

I have a upload script that reads a csv file then replaces the contents. Currently the script just grabs a csv file, but id like to be able to grab csv feeds that are compressed . I have a script for this but it doesnt seem to work.. Any help would be appreciated.

 

This is my old code

$to_rep = array_keys($arr);
$file = 'affiliatefuture.csv'; //file name here
$lines = file($file);


foreach($lines as $k=>$line) {

 

This is the new code

$url = 'http://datafeed.api.productserve.com/compression/gzip/';

//grabbing whole file at once
foreach (file("compress.zlib://$url") as $line) {
    $data = explode(',', $line);
    var_dump($data);
}

//one line at a time to conserve memory (better for very large files)
$file = fopen("compress.zlib://$url", 'r');
while ($data = fgetcsv($file)) {
    var_dump($data);
}
fclose($file);

$lines = file($file);


foreach($lines as $k=>$line) {

Link to comment
https://forums.phpfreaks.com/topic/149138-solved-get-csvgzip-file/
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.