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