суббота, 3 августа 2013 г.

PHP: Force the browser to download the text in file

    PHP: Force the browser to download the text in file


    1. $text_in_file = 'Put some text here';
    2.  
    3. if (isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
    4. Header('Content-Type: application/force-download');
    5. else
    6. Header('Content-Type: application/octet-stream');
    7.  
    8. Header('Accept-Ranges: bytes');
    9. Header('Content-Length: ' . strlen($text_in_file)); // text to file
    10. Header('Content-disposition: attachment; filename="downloaded_filename.txt"');
    11.  
    12. echo $text_in_file;
    13. exit();

Комментариев нет:

Отправить комментарий

Постоянные читатели

Популярные сообщения