How to bring up a download box in php

Source: Internet
Author: User
When creating an image download site, users often need to download images, but the image browser can open them directly. what should I do? Is there any way to download an image file in the pop-up download box? phperz.com certainly does, the php header function can provide this method. You can copy the following code from the php programmer's house.

When creating an image download site, users often need to download images, but the image browser can open them directly. what should I do? Is there any way to download an image file in the pop-up download box? phperz.com certainly does, the php header function can provide this method. You can copy the following code from the php programmer's house.

In progressImageDownloadWhen the site, you often needDownloadImage,ImageThe browser can be opened directly. What should I do?MethodAllowsImageType file pop-upDownloadBoxDownloadPhperz.com

Of course, some php header functions can provide suchMethodPhp programmer's house

You can copy the following code to test www.phperz.com.

Reference content is as follows:
$ Filename = "123.jpg ";//ImageAddress, either absolute or relative.
Header ("Content-Type: application/force-download ");
Header ('content-Disposition: attachment; filename = "'. $ filename .'"');
$ Img = file_get_contents ($ filename );
Echo $ img;
?>

Www.phperz.com

The effect is as follows: www.phperz.com

Www.phperz.com

The key point is the php programmer's house.

Header ("Content-Type: application/force-download ");
Header ('content-Disposition: attachment; filename = "'. $ filename .'"');

Phperz ~ Com

These two lines of code allow the browser to be forcedDownloadFile

Phpzer

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.