Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What file types does header("Content-Encoding: gzip") support?

Tags:

php

I'm using this snippet:

// ... snip

header("Content-Encoding: gzip");
include some_file;

// ... snip

to serve zipped content.

What types of encoding can I serve this way. i.e what can i put in for some_file?


2 Answers

This just tells the receiver that the sender compressed the payload using gzip compression algorithm and it will need to be decompressed when received. For example a server may compress a very large page and send it to the client, the client will need to decompress it before it can be processed further.

As @Evert points out, the client must be able to accept gzipped data.

This does not have anything to do with downloading gzip archives so file type is irrelevant.

If you want to specify the type of file being downloaded, this is done with the Content-Type header. For example:

header("Content-Type: application/gzip"); // for GZIP archive files
header("Content-Type: application/zip"); // for ZIP archive files

Or more generically:

header("Content-Type: application/octet-stream"); // for arbitrary binary data
like image 56
Dave Rager Avatar answered Oct 19 '25 01:10

Dave Rager


Everything, as long as it's gzipped. But you should only serve files like that if the client sends: Accept-Encoding: gzip

like image 27
Evert Avatar answered Oct 19 '25 01:10

Evert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!