Code for PHP download file

Source: Internet
Author: User

This article is about the PHP download file code, has a certain reference value, now share to everyone, the need for friends can refer to the

 Public function down () {header (' Content-type:application:json;charset=utf8 ');        Header (' access-control-allow-origin:https://coucouchina.com ');        Header (' Access-control-allow-methods:post ');        Header (' Access-control-allow-headers:x-requested-with,content-type ');        Header ("Content-type:text/html;charset=utf-8");//$file _name= "cookie.jpg";        $file _name = "apple-app-site-association";//To solve the problem of Chinese can not be displayed $file _name = Iconv ("Utf-8", "gb2312", $file _name); $file _sub_path = $_server[' Document_root ').                "/"; $file _path = $file _sub_path.            $file _name;//first to determine if the given file exists or not (!file_exists ($file _path)) {echo "does not have the file file";        Return        } $fp = fopen ($file _path, "R");        $file _size = filesize ($file _path);//Headers ("Content-type:application/octet-stream") to be used for downloading files;        Header ("Accept-ranges:bytes"); Header ("Accept-length:".)        $file _size); Header ("content-disposition:attachment; Filename= ".        $file _name);        $buffer = 1024;  $file _count = 0;//returns data to the browser while (!feof ($fp) && $file _count < $file _size) {$file _con                    = Fread ($fp, $buffer);                    $file _count + = $buffer;        echo $file _con;    } fclose ($FP); }

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.