phpheader头输出不同⽂档
function _serveFile($key) {
ini_set("memory_limit","128M");
$file = $this->_data[$key];
if(isset($file) && !empty($file)) {
$ext = end(explode(".", $file));
$allowed = array("doc","rtf","txt","pdf","xls","jpg","png","tiff","jpeg");
//if(in_array($ext,$allowed)) {
if(1) {
switch($ext) {
case "txt":
$type = "text/plain";
break;
case "rtf":
$type = "application/rtf";
break;
case "doc":
$type = "application/msword";
break;
case "docx":
$type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
case "xls":
$type = "application/vnd.ms-excel";
break;
case "pdf":
$type = "appliction/pdf";
break;
case "png":
$type = "image/png";
break;
case "gif":
$type = "image/gif";
break;
case "jpg":
case "jpeg":
$type = "image/jpeg";
break;
case "tiff":
$type = "image/tiff";
break;
default:
$type = "application/octet-stream";
break;
}
$name = $this->_data['first_name']."_".$this->_data['last_name']."_".$key.".".$ext;
$tmp = $this->_createDecryptedTmpFile(UPLOAD_DIR.DS."files".DS.$file);
header("Pragma:public");
header("Expires:0");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Cache-Control:private",false);
header("Content-Type:application/force-download");
header("Content-Type:application/download");
header("Content-Description:File Transfer");
header("Content-type:".$type);
header("Content-disposition: attachment; filename=".$name);
header("Content-Length:".filesize($tmp));
echo file_get_contents($tmp);
} else {
echo "The file type $ext is not allowed";
}
}
}
php中header是什么意思<?php
$File_Name=$_GET['file'];$File_Type = substr($File_Name, -4);switch ($File_Type){ Case ".mp3": $ContentType = "audio/mpeg3"; $File_Path="Music_
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论