Home >Backend Development >PHP Tutorial >A brief analysis of the method of forcing downloading of files in PHP

A brief analysis of the method of forcing downloading of files in PHP

WBOY
WBOYOriginal
2016-07-25 08:54:49957browse
  1. $filename = "test.txt";
  2. header ("Content-Type: application/force-download");
  3. header ('Content-Disposition: attachment;filename="'. $filename.'"');
  4. readfile ($filename);
Copy the code

This way, the file can be downloaded directly instead of opened.

Principle analysis: 1. header ("Content-Type: application/force-download"); //Force download; 2. header ('Content-Disposition: attachment; filename="'.$filename.'"'); //Implement file download. Finally, readfile($filename) reads the file for download.



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