Web Hosting Talk







View Full Version : PHP and .gz ! Need Help!!


Fahad_1
11-24-2006, 05:30 AM
Hello,

I need help with .gz for a php script.

I have uploaded a file.gz in my server. Its more than 18 mb in size and 25mb when unzipped.

Its wud be really a pain if I go for uploading each and every file one by one without .gz.

Now, I want a php script that will extract, for e.g, the file.txt.gz to file.txt in the same location of the server.

Can anyone help me with the script pls.


Thanks

brendandonhu
11-24-2006, 03:02 PM
See the comments here: http://us2.php.net/zlib

Fahad_1
11-25-2006, 05:20 AM
Hello, I found this script from ur given url :

function uncompress( $srcFileName, $dstFileName, $fileSize )
{
// getting content of the compressed file
$zp = gzopen( $srcFileName, "r" );
$data = fread ( $zp, $fileSize );
gzclose( $zp );

// writing uncompressed file
$fp = fopen( $dstFileName, "w" );
fwrite( $fp, $data );
fclose( $fp );
}


And I used the function this way :
<?
uncompress("file.txt.gz", "file.txt", filesize("file.txt.gz"));
?>


But unfortunately, it just copied the original file to file.txt without uncompressing it.

The uncompressed file should have been more than 24mb in size. but its still the same (16mb).

Is there anyth wrong in the codes?

brendandonhu
11-25-2006, 05:25 AM
Try using gzread() instead of fread().

Fahad_1
11-25-2006, 05:28 AM
I got it! Thanks man!

Actually the variable filesize is the size of the file in extracted form.

it worked fine!

Thanks!:)