- Header ("Cache-control:public");
- Header (' Content-type:application/vnd.ms-excel ');
- Header ("content-disposition:attachment; Filename=report.xls ");
Copy CodeIf you don't add the first sentence, it pops up: Internet Explorer cannot download **.php (from * * website). Internet Explorer cannot open the Internet site. The requested Web site is not available, or cannot be found, please try again later. And even the name is not the name of the set: Report.xls, but **.php, the first sentence to add on it. Look at Rar,gif and the like, do not add the first sentence, incredibly through, do not pop the error box! If it is GIF and other pictures, content-disposition:attachment; A Save dialog box is forced to pop up. If omitted or inline, it will be displayed directly on the page. The content-type should be evaluated as follows:
Switch ($file _extension) {
- Case "PDF": $ctype = "Application/pdf"; Break
- Case "EXE": $ctype = "Application/octet-stream"; Break
- Case "Zip": $ctype = "Application/zip"; Break
- Case "Doc": $ctype = "Application/msword"; Break
- Case "xls": $ctype = "application/vnd.ms-excel"; Break
- Case "ppt": $ctype = "Application/vnd.ms-powerpoint"; Break
- Case "gif": $ctype = "Image/gif"; Break
- Case "png": $ctype = "Image/png"; Break
- Case "JPEG":
- Case "jpg": $ctype = "image/jpg"; Break
- Case "MP3": $ctype = "Audio/mpeg"; Break
- Case "wav": $ctype = "Audio/x-wav"; Break
- Case "MPEG":
- Case "MPG":
- Case "MPE": $ctype = "Video/mpeg"; Break
- Case "mov": $ctype = "Video/quicktime"; Break
- Case "avi": $ctype = "Video/x-msvideo"; Break
The following is for extensions that shouldn ' t is downloaded (sensitive stuff, like PHP files)
- Case "PHP":
- Case "htm":
- Case "HTML":
- Case ' txt ': Die ("cannot is used for". $file _extension. "Files!"); Break
Default: $ctype = "Application/force-download";
- }
Copy Code |