Author: xling
First look at the download of the xls file:
//header("Cache-Control: public");
header('content-type:application/vnd.ms-excel' );
header("Content-Disposition:attachment; filename=report.xls");
If you do not 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 and it will be OK.
When I was watching 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.
The above is what I researched using a stupid method (I couldn’t find the available documents, so I had to try them one by one).
The following is the value that Content-type should take,
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";
}