Re: [PHP-DB] force to download file

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

 



On Dec 17, 2007 3:13 PM, Hiep Nguyen <hnguyen@xxxxxxxxxxxxxxxx> wrote:
> hi all,
>
> 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?
>
> thanks

    Hiep,

    This is a question that should've been asked on the PHP General
list, so I'm reply-all'ing and sending it to the General list for the
archives as well.

    Here's a function I use that should help you out.

<?
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";
    }
}
?>


-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux