Main Content
Setting the file name for a downloaded document Archive - Originally posted on "The Horse's Mouth" - 2005-11-03 16:34:26 - Graham Ellis
When you're writing a script to send a file to a browser, you can force it to be saved as a file using a content type header, and you can give it a name different to your script by using a content disposistion. In PHP, you might write
header("content-type: application/octet-stream\n".
"content-disposition: attachment; filename=\"$var.txt\"\n");
Remember - if you're going to call the header function, you MUST do it before you send any output to the browser!
Some other articles
H112 - Further Web Page and Network Handling Moving from mysql to mysqli - simple worked example Passing variable between PHP pages - hidden fields, cookies and sessions Multiple page web applications - maintaining state - PHP Telling which ServerAlias your visitor used - useful during merging domains Easy session example in PHP - keeping each customers data apart 3 digit HTTP status codes - what are they, which are most common, which should be a concern? Sending out an email containing HTML from within a PHP page Downloading a report from the web for further local analysis Uploading a document or image to its own URL via a browser How to build a test harness into your PHP Shipping a test harness with your class in PHP http, https and ajp - comparison and choice Downloading data for use in Excel (from PHP / MySQL) Keeping staff up to date on hotel room status Script to present commonly used images - PHP PHP / Web 2 logging Single login and single threaded models - Java and PHP Copyright and theft of images, bandwidth and members. Simple page password protection - PHP .php or .html extension? Morally Static Pages PHP header() function - uses and new restrictions Updating a page strictly every minute (PHP, Perl) Improving searches - from OR to AND? PHP Image upload script Passing GET parameters through Apache mod_rewrite Global, Superglobal, Session variables - scope and persistance in PHP Of course I'll tell you by email Image maps for navigation - a straightforward example Hot answers in PHP Finding the language preference of a web site visitor Adding PHP tags to an old cgi program PHP - setting sort order with an associative array Using PHP to output images, XML, Style sheets, etc Morning image, afternoon image Daily Image Santafied This article Accessing a page via POST from within a PHP script Server side scripting of styles to suit the browser Caching an XML feed Reading a news or blog feed (RSS) in your PHP page What brings people to my web site? Time calculation in PHP Sudoku helper or sudoku cheat Spotting a denial of service attack What language is this written in? When to use Frames A207 - HTTP 3 digit HTTP status codes - what are they, which are most common, which should be a concern? Downloading a report from the web for further local analysis What is all this SESSION stuff about? (PHP) Http protocol - what does a web server send Uploading and Downloading files - changing names (Perl and PHP) http, https and ajp - comparison and choice Web page (http) error status 405 Etag in http headers - what is it? This article