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
Release: 2016-07-25 08:54:49
Original
954 people have browsed it
  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.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template