This code does the trick
// Name of the file we're compressing
$file = "test.txt";
// Name of the gz file we're creating
$gzfile = "test.gz";
// Open the gz file (w9 is the highest compression)
$fp = gzopen ($gzfile, 'w9');
// Compress the file
gzwrite ($fp, file_get_contents($file));
// Close the gz file and we're done
gzclose($fp);
Related Contents:
- Which compression method to use in PHP?
- Content-Length not sent when gzip compression enabled in Apache?
- Decode gzipped web page retrieved via cURL in PHP
- How to reduce the image size without losing quality in PHP [closed]
- PHP equivalent of .NET/Java’s toString()
- How to read a large file line by line?
- Why doesn’t this code simply print letters A to Z?
- php execute a background process
- Unzip a file with php
- array_push() with key value pair
- What’s the deal with a leading underscore in PHP class methods?
- How can I get PHPUnit MockObjects to return different values based on a parameter?
- How to delete object from array inside foreach loop?
- Get characters after last / in url
- How do I turn off PHP Notices?
- How to check if an array value exists?
- Replacing accented characters php
- HTTP requests with file_get_contents, getting the response code
- Best way to document Array options in PHPDoc?
- What is the equivalent of php’s print_r() in python?
- Using `$this` in an anonymous function in PHP pre 5.4.0
- How to install PHP composer inside a docker container
- install ext-zip for Mac
- PHP: Serve a file for download without providing the direct link
- JetBrains WebIDE: PHP variable type hinting?
- PHP buffer ob_flush() vs. flush()
- Sorting a php array of arrays by custom order
- BitTorrent: Download not starting
- What is the PHP syntax to check “is not null” or an empty string? [duplicate]
- How do I reload a relation collection in laravel?
- What is the format for e-mail headers that display a name rather than the e-mail?
- How to require PHP files relatively (at different directory levels)?
- PHP Data-URI to file
- How can I get the authenticated user name under Apache using plain HTTP authentication and PHP?
- How to access constant defined in child class from parent class functions?
- CakePHP: Find where field is not null
- Serializing and submitting a form with jQuery and PHP
- How to create a foreign key in phpmyadmin
- How to get current logged in user using WordPress Rest Api?
- phpmailer – The following SMTP Error: Data not accepted
- How to read the response effective URL in Guzzle ~6.0
- Strategy for developing namespaced and non-namespaced versions of same PHP code
- RegExp to strip HTML comments
- Stop script execution upon notice/warning
- When to wrap curly braces around a variable
- How to get the path of a derived class from an inherited method?
- Alternative to money_format() function
- Array_map function in php with parameter
- MySQL and NoSQL: Help me to choose the right one
- Automatic PHP Documentation Generation? [closed]