how to force kmz file download with php

Asked

Viewed 130 times

0

I am having difficulty to force a download of a file type kmz (google file Earth), it is made to download but the file gets corrupted, someone can help me?

$filename = "../kmz/".$_GET['id'];
        $filename = realpath($filename);

        $file_extension = strtolower(substr(strrchr($filename,"."),1));


        if (!file_exists($filename)) {
            die("NO FILE HERE");
        }
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false);
        header("Content-Type: application/force-download");
        header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".@filesize($filename));
        set_time_limit(0);
        @readfile("$filename") or die("File not found.");
  • vc is closing the php tag(?>) ?

  • yes, it is working with other file types with pdf, jpg , rar and other however kmz does not work

  • Try to remove it if possible, sometimes extra characters are added with the closing tag which end up 'corrupting' the file.

  • remove closing tag?

  • Yes, it has html after closing tag?

  • has no, it’s just this snippet of code and with the opening and closing php tags

  • believe q the file is of unknown extension

  • I have tried using Content-Type: Unknown/Unknown also failed

Show 3 more comments

1 answer

0

Put this in your file . htaccess: Addtype application/octet-stream . kmz

then to download, just create a link or go to the URL pointing directly to your file. Ex: http://www.example.com/link.kmz

  • where I find this file . htaccess?

  • If the . htaccess file does not exist, you must create it within the folder where the site access page is located. (Ex: www/index.php - www/. htaccess)

  • the file must contain this code? Addtype application/octet-stream . kmz <Files 403.shtml> order allow,Deny allow from all </Files>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.