4

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 2

6

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
0
4

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

4
  • I was under the impression that most ( if not all ) modern browsers (clients) accept this?
    – user1637281
    Jun 11, 2013 at 16:40
  • Pretty much all browsers will, yea. It's still smart to be robust and compliant with HTTP. That means only sending back gzipped data when the client requested it.
    – Evert
    Jun 11, 2013 at 17:00
  • ...how would I know if the client requested it, from the server side, is there a PHP parameter I can check?
    – user1637281
    Jun 11, 2013 at 17:35
  • yea, it's in $_SERVER['HTTP_ACCEPT_ENCODING']. Anyway, I think your question is answered. You can easily find more information by googling the subject
    – Evert
    Jun 11, 2013 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.