gzread zip problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amolkad
Forum Newbie
Posts: 22
Joined: Tue Jun 01, 2004 7:22 am

gzread zip problem

Post by amolkad »

HI,

Follwoing is code I am using for reading zip and writing in another file.
But it do not read complete file.It may be filesize problem.
My zlib version is 1.2.0.7
PHP Version 4.3.3
Apache 2.0

function gunzip($filename,$destfile)
{
$zp = gzopen($filename, "r");
$fp = fopen($destfile, "w");
fputs($fp, gzread($zp, filesize($filename))) ;
fclose($fp);
gzclose($zp);
}
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If all your doing is opening it, reading it and writing out to another file, why not just use copy ?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you shouldn't use filesize($filename) as a parameter to gzread:
PHP Manual wrote: gzread() reads up to length bytes from the gz-file pointer referenced by zp. Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

markl999 wrote:If all your doing is opening it, reading it and writing out to another file, why not just use copy ?
He's decompressing the file, not just copy it.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

He's decompressing the file, not just copy it.
Ah, quite right.
/me stops trying to help at 7:20am and no sleep
amolkad
Forum Newbie
Posts: 22
Joined: Tue Jun 01, 2004 7:22 am

Post by amolkad »

Thanks for help,

I will try by removing filesize.
Post Reply