Re: [PHP] Re: [PHP-DB] force to download file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i have this on top of my php page:

header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: inline; filename=excelfile.xls");

but it is not prompt to save the file instead it opens right in IE.

my question is how do i force the browser prompts to save the file?

<?php
    header('Content-Disposition: attachment; filename="'.$filename.'"');
?>

That should do the trick, but if not then try adding the Content-Type header from below.

<?
function force_download($filename,$dir='./') {
    if ((isset($file))&&(file_exists($dir.$file))) {
        header("Content-type: application/force-download");
        header('Content-Disposition: inline; filename="'.$dir.$filename.'"');
        header("Content-Transfer-Encoding: Binary");
        header("Content-length: ".filesize($dir.$filename));
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.$filename.'"');
        readfile($dir.$filename);
    } else {
        echo "No file selected";
    }
}
?>

FYI You have Content-Disposition twice; you only need the second.

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux