Php files are downloaded and encapsulated into a class with three more bytes.

Source: Internet
Author: User
Php files are encapsulated into a class with three more bytes. what is wrong? & Nbsp; class & nbsp; FileDown & nbsp ;{& nbsp; & nbsp; & nbsp; public & nbsp; $ When the php file is downloaded and encapsulated into a class, there are always three more bytes. what is wrong?

Class FileDown {
Public $ fileName;
Public $ fileSize;
// Transcode gb2312
Function _ construct ($ fileName ){
$ This-> fileName = iconv ("UTF-8", "gb2312", $ fileName );
}
Function Down (){
// $ _ SERVER ['document _ root'] ROOT directory of the file where the script is currently running. Defined in the server configuration file.
$ Path = $ _ SERVER ['document _ root']. "/12/". $ this-> fileName;
If (! File_exists ($ path )){
Die ("file does not exist ");
}
$ Fp = fopen ($ path, "r"); // Read
$ This-> fileSize = filesize ($ path );
// The browser that returns the file header identifies the download by header // returns
// The returned file type stream can be text binary
Header ("Content-type: application/octet-stream ");
// Returns the value in bytes.
Header ("Accept-Ranges: bytes ");
// Returns the file size.
Header ("Accept-Length: $ this-> fileSize ");
// The pop-up dialog box on the client, with the corresponding file name
Header ("Content-Disposition: attachment; filename =". $ this-> fileName );
$ Count = 0;
$ Buffer = 1024;
While (! Feof ($ fp) & $ this-> fileSize-$ count> 0 ){
$ FileData = fread ($ fp, $ buffer );
$ Count + = $ buffer;
Echo $ fileData;
}
Fclose ($ fp );
}
}
$ Fd = new FileDown ("landline .png ");
$ Fd-> Down ();
Share: More

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.