How can php or html web pages download files and open files?

Source: Internet
Author: User
On a php or html webpage, there is a file link on it. When you click it, how does it open the file? How does it download it? The download dialog box appears. On a php or html webpage, there is a file link on it. When you click it, how does it open the file? How does it download it? The download dialog box appears.

Reply content:

On a php or html webpage, there is a file link on it. When you click it, how does it open the file? How does it download it? The download dialog box appears.

In this way, the file is downloaded:

Function downloadfile ($ filename, $ storage) {if (! Is_file ($ storage) exit ('the file does not exist! '); If (! $ Fp = fopen ($ storage, 'R') exit ('error'); header ('content-Type: application/octet-stream; charset = UTF-8 '); if (preg_match ("/Trident/", $ _ SERVER ["HTTP_USER_AGENT"]) {header ('content-Disposition: attachment; filename = "'. utf8togbk ($ filename ). '"');} else {header ('content-Disposition: attachment; filename = "'. $ filename. '"');} header ('content-Transfer-Encoding: binary '); while (! Feof ($ fp) {echo fread ($ fp, 1025) ;}fclose ($ fp );}

Should I open a file in a browser?

You can use the php header () method to modify the content of the html header.

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.