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

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

藏色散人
Release: 2023-02-26 14:20:01
Original
3025 people have browsed it

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);
?>
Copy after login

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!

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template