Header Save Data in PHP – Force File Download Using PHP

by Hiroshi on June 19, 2008

in Header, PHP Basics

If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf

Related Posts

  • Header Redirect Location in PHP Here is how we redirect a page. The page will be redirected to specified URL.
  • Simple PHP Script – Lets Start PHP – Echo Hello PHP If you want to learn PHP you have come to the right place. I will not only teach you how […]
  • PHP Post And Get Post and Get are both used in forms to pass data from one page to another but there is a […]
  • PHP Echo in PHP PHP function echo is a means of outputting text to the web browser. Here is how we can […]
  • PHP Strings Before you can use a string you have to create it! A string can be used directly in a […]
  • PHP Functions A function is just a name we give to a block of code that can be executed whenever we […]
  • PHP Arrays An array is a data structure that stores one or more values in a single value. In more […]
  • Data Types In PHP Data types are many e.g. Boolean, Integer, Double (or float), String and there might be […]
  • Define Variable In PHP A variable is a means of storing a value, such as text string "Hello World!" or the […]
  • Action At Link Using PHP Use this example to show some hidden message at page using PHP. You can use two pages […]

Previous post:

Next post: