-
- //header("Cache-Control: public");
- header('content-type:application/vnd.ms-excel');
- header("Content-Disposition:attachment ; filename=report.xls");
Copy the code If you don’t add the first sentence, it will pop up: Internet Explorer cannot download **.php (from ** website). Internet Explorer cannot open the internet website. The requested website is unavailable or cannot be found. Please try again later.
And even the name is not the set name: report.xls, but **.php, just add the first sentence.
When I was looking at rar, gif and the like, without adding the first sentence, it passed without the error box popping up!
If it is a picture such as gif, Content-Disposition:attachment; will force a save dialog box to pop up. If omitted or inline, it will be displayed directly on the web page.
Content-type should take a value 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 are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
- case "php":
- case "htm":
- case "html":
- case "txt": die("Cannot be used for ". $file_extension ." files!"); break;
default: $ctype="application/force-download";
- }
-
Copy code
|