Home  >  Article  >  Backend Development  >  When php clicks on a link, it downloads instead of opening it.

When php clicks on a link, it downloads instead of opening it.

藏色散人
藏色散人Original
2019-10-14 10:03:102860browse

When php clicks on a link, it downloads instead of opening it.

php method to realize that clicking a link downloads instead of opening it

Hyperlink connected to txt text , do not open it directly but download it after clicking

Two processing methods on the server side, one is to set it in a server such as apache or iis or tomcat, or specify the sending type in the program.

This information belongs to http header information, and PHP has a function to directly operate the header information.

How to implement php:

The code is as follows:

<?php
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($_GET[&#39;url&#39;]));
readfile($filename);
?>

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of When php clicks on a link, it downloads instead of opening it.. For more information, please follow other related articles on the PHP Chinese website!

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