[PHP] get zip file when visiting browser

With Apache + PHP
This code allows us to download a file zip from browser:


<?php

    $your_zip_file = "/path/to/your_zip_file.zip";

    $file_name = basename($yourfile);

    header("Content-Type: application/zip");
    header("Content-Disposition: attachment; filename=$file_name");
    header("Content-Length: " . filesize($your_zip_file ));

    readfile($your_zip_file );
    exit;

?> 
Advertisements

One comment on “[PHP] get zip file when visiting browser

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s