Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract or uncompress gzip file using php? [duplicate]

function uncompress($srcName, $dstName) {     $sfp = gzopen($srcName, "rb");     $fp = fopen($dstName, "w");      while ($string = gzread($sfp, 4096)) {         fwrite($fp, $string, strlen($string));     }     gzclose($sfp);     fclose($fp); } 

I tried this code but this does not work, I get:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

like image 751
Farzam Tahmasebmirza Avatar asked Jun 29 '12 16:06

Farzam Tahmasebmirza


People also ask

How do I unzip a .GZ file and keep original?

We can use the -d option with gzip command to decompress the . gz compressed files. Same as in the compression, we can use the -k option to keep the original compressed file and decompress it.

How do I view .GZ files without extracting?

Just use zcat to see content without extraction. From the manual: zcat is identical to gunzip -c . (On some systems, zcat may be installed as gzcat to preserve the original link to compress .)


1 Answers

Try this found here

//This input should be from somewhere else, hard-coded in this example $file_name = '2013-07-16.dump.gz';  // Raising this value may increase performance $buffer_size = 4096; // read 4kb at a time $out_file_name = str_replace('.gz', '', $file_name);   // Open our files (in binary mode) $file = gzopen($file_name, 'rb'); $out_file = fopen($out_file_name, 'wb');   // Keep repeating until the end of the input file while (!gzeof($file)) {     // Read buffer-size bytes     // Both fwrite and gzread and binary-safe     fwrite($out_file, gzread($file, $buffer_size)); }  // Files are done, close files fclose($out_file); gzclose($file); 
like image 174
Vasu Avatar answered Sep 28 '22 04:09

Vasu