PHP Function GZDecode - 30+ Real World Examples
PHP's gzdecode function takes a zipped string and decodes it. The output is a deflated string. This can be used to save bandwidth when sending large amounts of data over the web or simply because some web servers don't support gzip compression at all.
There are 30+ real world examples of php function gzdecode in use on the internet. They are contributed by our community of developers.
The first thing you'll need is to make sure your zipped file was made with the gzip option. This can be done with a simple command line test on a command prompt (not the web browser).
Next, you'll want to unzip your file with this handy php function. This uses the gzread function, so it is really fast and easy to use. It has error handling built in too, so if you try to read an already existing file, it will throw an exception and not continue.
There are some optional arguments to this function, such as a maximum length of data that should be read in one chunk, and whether or not you want to overwrite the previous contents of your zipped file. You can also set the recursion limit of the gzread function if you need to control how much memory it consumes.
The level of compression, can be 0 for no compression up to 9 for maximum compression. The encoding mode, can be FORCE_GZIP or FORCE_DEFLATE. Prior to PHP 5.4.0, using FORCE_DEFLATE produces RFC 1950 compliant output that includes a gzip header, the deflated data, and an Adler checksum at the end of the output.