<?
include $_SERVER["DOCUMENT_ROOT"]."/include/lib.php";
?>
<?
// 9. 파일 이름과 실제 파일
$dir = $_SERVER["DOCUMENT_ROOT"]."/images";
$file_path = $dir."/a.jpg";
$original = "a.jpg";
$HTTP_USER_AGENT = $_SERVER[HTTP_USER_AGENT];
// 10.파일이 있으면
if (file_exists($file_path)) {
// 11. 다운로드 헤더 만들기
if(eregi("(MSIE 5.0|MSIE 5.1|MSIE 5.5|MSIE 6.0)", $HTTP_USER_AGENT))
{
if(strstr($HTTP_USER_AGENT, "MSIE 5.5"))
{
header("Content-Type: doesn/matter");
header("Content-disposition: filename=$original");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
}
if(strstr($HTTP_USER_AGENT, "MSIE 5.0"))
{
Header("Content-type: file/unknown");
header("Content-Disposition: attachment; filename=$original");
Header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
}
if(strstr($HTTP_USER_AGENT, "MSIE 5.1"))
{
Header("Content-type: file/unknown");
header("Content-Disposition: attachment; filename=$original");
Header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
}
if(strstr($HTTP_USER_AGENT, "MSIE 6.0"))
{
Header("Content-type: application/x-msdownload");
Header("Content-Length: ".(string)(filesize("$file_path")));
Header("Content-Disposition: attachment; filename=$original");
Header("Content-Transfer-Encoding: binary");
Header("Pragma: no-cache");
Header("Expires: 0");
}
} else {
Header("Content-type: doesn/matter");
Header("Content-Length: ".(string)(filesize("$file_path")));
Header("Content-Disposition: attachment; filename=$original");
Header("Content-Description: PHP3 Generated Data");
Header("Pragma: no-cache");
Header("Expires: 0");
}
flush();
// 12. 파일을 읽어 내보내기
if (is_file($file_path)) {
$fp = fopen($file_path, "rb");
while(!feof($fp)) {
echo fread($fp, 100*1024);
flush();
}
fclose ($fp);
flush();
}
} else {
echo $alert_header;
alert("파일이 존재 하지 않습니다.");
}
?>
[출처] : PHPer's Heaven http://handsome.pe.kr/