Home  >  Article  >  Backend Development  >  PHP header function directly prompts the saved code when downloading the file

PHP header function directly prompts the saved code when downloading the file

WBOY
WBOYOriginal
2016-07-25 09:00:36848browse
  1. $filename = 'path + actual file name';
  2. //Type of file
  3. header('Content-type: application/pdf');
  4. //Name displayed when downloading
  5. header ('Content-Disposition: attachment; filename="Save file name.pdf"');
  6. readfile("$filename");
  7. exit();
  8. ?>
Copy code

Provide an online withdrawal There are many ways to implement downloading using php header functions.

  1. if (isset($link))
  2. {
  3. Header("HTTP/1.1 303 See Other");
  4. Header("Location: $link");
  5. exit;
  6. }
  7. ?>
Copy the code

$link is the actual path of the file.

Attached is a list of Content-Type types of HTTP headers that the server responds to.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn