note 41810 modified in function.header by tomsommer

From: Date: Thu, 22 Apr 2004 20:22:00 +0000
Subject: note 41810 modified in function.header by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-68544@lists.php.net to get a copy of this message
In response to Martin Anso and for your benefit, here's an even better routine for forcing the browser to save a file, rather than opening it. ----------- $f = fopen("file.txt", "rb"); $content_len = (int) filesize($f, "file.txt"); $content_file = fread($f, $content_len); fclose($f); $output_file = 'something.txt'; @ob_end_clean(); @ini_set('zlib.output_compression', 'Off'); header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header('Content-Transfer-Encoding: none'); header('Content-Type: application/octetstream; name="' . $output_file . '"'); //This should work for IE & Opera header('Content-Type: application/octet-stream; name="' . $output_file . '"'); //This should work for the rest header('Content-Disposition: inline; filename="' . $output_file . '"'); header("Content-length: $content_len"); echo $content_file; exit(); --was-- In response to Martin Anso and for your benefit, here's an even better routine for forcing the browser to save a file, rather than opening it. ----------- $f = fopen("file.txt", "rb"); // use "rb" just in case this is used on a windows server :)) $content_len = (int) filesize($f, "file.txt"); $content_file = fread($f, $content_len); fclose($f); $output_file = 'something.txt'; @ob_end_clean(); @ini_set('zlib.output_compression', 'Off'); header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header('Content-Transfer-Encoding: none'); header('Content-Type: application/octetstream; name="' . $output_file . '"'); //This should work for IE & Opera header('Content-Type: application/octet-stream; name="' . $output_file . '"'); //This should work for the rest header('Content-Disposition: inline; filename="' . $output_file . '"'); header("Content-length: $content_len"); echo $content_file; exit(); ------- Hope this helps you all :))) Boby form http://www.motion-hosting.com http://www.php.net/manual/en/function.header.php

« previous php.notes (#68544) next »