Jump to content

Unzipping .gz and .tar files with php


mrphobos

Recommended Posts

I'm attempting to use php to automate the process of unzipping the contents of a number of .gz and .tar files I have into a folder. I've spend several hours weighing my options and at this simple noob planing stage I'd just like to know what my options are.

 

The only commands that are built into php that appear to be useful in this effort are the zlib library. I've found zlib.output_compression on my server and enabled it so am I correct in assuming I can use these functions now?

 

 

Zlib Functions

gzclose — Close an open gz-file pointer

gzcompress — Compress a string

gzdecode — Decodes a gzip compressed string

gzdeflate — Deflate a string

gzencode — Create a gzip compressed string

gzeof — Test for EOF on a gz-file pointer

gzfile — Read entire gz-file into an array

gzgetc — Get character from gz-file pointer

gzgets — Get line from file pointer

gzgetss — Get line from gz-file pointer and strip HTML tags

gzinflate — Inflate a deflated string

gzopen — Open gz-file

gzpassthru — Output all remaining data on a gz-file pointer

gzputs — Alias of gzwrite

gzread — Binary-safe gz-file read

gzrewind — Rewind the position of a gz-file pointer

gzseek — Seek on a gz-file pointer

gztell — Tell gz-file pointer read/write position

gzuncompress — Uncompress a compressed string

gzwrite — Binary-safe gz-file write

readgzfile — Output a gz-file

zlib_get_coding_type — Returns the coding type used for output compression

 

Secondly, I don't understand which function I need to use for this. I just want to take the contents of a .gz or .tar folder and place them in another. I don't think I'm grasping the language of the php documentation. Take for instance "readgzfile"s description, "Reads a file, decompresses it and writes it to standard output." Does that mean it decompresses the file and takes it's content and outputs them? It doesn't appear to based on it's properties.

 

Any help any of you could give me would be greatly appreciated. I'm not looking for a hand out, I'm just looking for which path to take. Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/200487-unzipping-gz-and-tar-files-with-php/
Share on other sites

http://www.devshed.com/c/a/PHP/TAR-File-Management-With-PHP-Archive-Tar/

this is a good tutorial on using pear to manage tar files.

 

As for Zlib, just think of the open/read/write/close functions the same manner as you would use fopen and its parts. In fact just think of any Zlib function as its comparable, by name, file function ie. gzseek == fseek.

fopen

fread/fwrite

fclose

...

gzopen

gzread/gzwrite

gzclose

 

You might also want to consider gzfile(), which you would use the same way as file(), it puts the contents of a gz file into an array just like file() does.

 

 

HTH

Teamatomic

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.