这个PHP代码的问题 [英] Problems with this php code
本文介绍了这个PHP代码的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,这是我使用php下载文件的代码,但是,当我下载文件(例如Excel 2007文件)时,excel不会打开它.问题出在哪里
Hello , this is my code to download files with php , but , when I download a file (for example Excel 2007 file) excel doesn''t open it. Where is the problem
$document = urldecode($_GET['download']);
$extension = end(explode('.',$document));
$mimetype = '';
switch($extension){
case 'zip':
$mimetype='application/zip';
break;
case 'rar':
$mimetype='application/x-rar-compressed';
break;
case 'xls':
$mimetype='application/vnd.ms-excel';
break;
case 'xlsx':
$mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
break;
case 'doc':
$mimetype='msword';
break;
case 'docx':
$mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document';
break;
case 'ppt':
$mimetype='application/vnd.ms-powerpoint';
break;
case 'pptx':
$mimetype='application/vnd.openxmlformats-officedocument.presentationml.presentation';
break;
}
header('Content-type:' . $mimetype);
header("Content-Disposition:attachment;filename:download.". $extension);
readfile($document);
推荐答案
document = urldecode(
document = urldecode(
_GET [' 下载']);
_GET['download']);
扩展名 = end(explode(' .',
这篇关于这个PHP代码的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文