How to use php to force a File Download box to pop up
Source: Internet
Author: User
When I work today, I need to force a Download box to be filled out after the user visits a page. I remember seeing the code snippet of this function on a forum. the result was not found, that's depressing. Later, Google came to a website and made a few decisions. at the same time, I would like to share with you the need to force a Download box after the user visits a page, I remember seeing the code snippet of this function on a forum. it was easy to find and the result was not found. it was depressing. Later, Google came to the game and made a few decisions. at the same time, I would like to share with you. The code is as follows:
$ Filename = "1.bmp"; // Image address, which can be an absolute or relative address
Header ("Content-Type: application/force-download ");
Header ('content-Disposition: attachment; filename = "'. $ filename .'"');
$ Img = file_get_contents ($ filename );
Echo $ img;
?>
This function is actually very practical. for example, in order to prevent other people from leeching resources, we should first provide a encrypted connection and users cannot download it after clicking it outside the site. Such a function needs to be implemented by the above code.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.