Home > Web Front-end > JS Tutorial > IE php code about forced downloading of files_javascript skills

IE php code about forced downloading of files_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:01:48
Original
1153 people have browsed it

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";
}

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template