1

I have a gzip file. Into this file I have many csv files. I want to read only one of these files that are contained into the gzip folder. The name of the gzip folder that I want to read is 'com.instore'. And the name of the csv file is 'second'.

I use the gzopen() to read the gzip folder. But now I don't know how to read the csv file contained inside.

  1. So, how can I do this?
  2. Do I have to close with the gzclose()?
  3. The gzip is into a server directory. How can I reach it?
Alex Dowining
  • 980
  • 4
  • 19
  • 41

2 Answers2

0

When you gzopen you dont uncompress it. you just creates a file pointer to it.

<?php
// get contents of a gz-file into a string
$filename = "/usr/local/something.txt.gz";
$zd = gzopen($filename, "r");
$contents = gzread($zd, 10000);
gzclose($zd);
?>

while $contents is your csv file as a string.

more info @ http://www.php.net/manual/en/function.gzread.php

Danilo Kobold
  • 2,562
  • 1
  • 21
  • 31
0

You can extract the gzip file using this: How can I extract or uncompress gzip file using php? and than using this: How to import csv file in PHP? populate the database.

Community
  • 1
  • 1
mrakodol
  • 1,143
  • 3
  • 12
  • 41