[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

Uncompressing .gz in php file

I need to know how to uncompress a .gz file in a php script I have tried several ways but it will not uncompress the file and write it to the hard drive

What I am doing is ftp to a site grab a .gz file that has a txt file in it I need to uncompress the gz file so I can use the txt file in another php script
0
txkhomes
Asked:
txkhomes
  • 3
  • 2
  • 2
1 Solution
 
steveiamCommented:
You can use popen() run another process, and send data to/from it.  You could popen("gzip -dc"), then feed it the compressed data, and read the decompressed data from it, without saving it (or anything) to disk.

  http://php.mirrors.ilisys.com.au/manual/en/function.popen.php

Or, if you have saved the .gz file to disk, you could use popen() or system() to call gzip to decompress it, with something like system("gzip -d compressed.gz");

  http://php.mirrors.ilisys.com.au/manual/en/function.system.php

Or, save it to disk and then have it decompress it on the fly with popen("gzip -dc compressed.gz").  Details on the command line options for gzip I'm using can be found here:

  http://www.freebsd.org/cgi/man.cgi?query=gzip&apropos=0&sektion=0&manpath=FreeBSD+6.0-RELEASE+and+Ports&format=html

If you're running PHP on a Windows-based machine, there is a Windows command-line version of gzip.
0
 
Nerd00Commented:
PHP includes the zlib library.

See this URL for the gzopen, gzread, and gzclose commands.

http://us3.php.net/manual/en/function.gzopen.php

Once you have the data in you can then write using the fopen, fwrite, fclose functions.

http://us3.php.net/manual/en/function.fopen.php

This way is more direct and it doesn't depend on certain commands being available on the system command line.
0
 
txkhomesAuthor Commented:
Can anyone give the language needed to do the following

ftp to site
grab archive and write to to y directory

unzip archive to x directory
exit
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
steveiamCommented:
You could do that in any number of languages, from a shell script (or batch file), though to PHP/C++/etc.
0
 
txkhomesAuthor Commented:
What I want is for it to be php and be called from a cron job
0
 
Nerd00Commented:
http://www.php.net is a good place to get information.

There is a set of functions that will allow you to get a files from an ftp site... Lookup "FTP"

There is a set of functions that will let you unzip gz files... Lookup "zlib"

There isn't much to it. I just don't have the time right now to write the code for you or I would.
0
 
txkhomesAuthor Commented:
I have no problem with closing this question
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now