Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Unzip a GZ file



6:49 pm on Apr 12, 2010 (gmt 0)

5+ Year Member

How do i unzip a GZ file in php directly.

I have a 600mb+ xyz.txt.gz file in my server that i want to extract directy in a file format (not reading the content into a string and then writing it to a file).
I know that the content in the xyz.txt.gz after unzipping is xyz.txt

Reading to a string and then writing to a file cause memory overload.

I have been able to unzip a xyz.zip file using the extractTo() provided by the ZipArchive extention but there is no such function under Zlib in php.

I do not have shell access to the server.

How do i do this in php.



8:40 pm on Apr 12, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there pemba76,

I vaguely recall that there is a filesize limit set somewhere, the easiest method would be to use exec or shell [uk.php.net ] I know that using an external program (make sure that the host/server has it installed obviously) will be ALOT quicker.

GzZip filetype support:-
[uk.php.net ]

Other than that, make sure that the zip format is done as .zip, that is though assuming as you are doing the zipping or can direct people that this is the only acceptable compression format.

Whenever I do file compression coding I always state that zip type is the only supported type that I work with, this then makes sure I don't get any coding headaches, though I am sure if I looked into it in more detail I could work out other ways - the joys of learning ;-p

Hope this helps you a little,



10:34 am on Apr 13, 2010 (gmt 0)

5+ Year Member

hi Matthew1980,
thanks for the response.
Well there is no way by which i can get the file in a .zip format. So i am only left with the option to use the .txt.gz file only.
I went through the links that you provided and would like to know how do i use the exex() to uncompress the .txt.gz file ?
Please guide.

Featured Threads

Hot Threads This Week

Hot Threads This Month