function
download(
$filepath
,
$newfilename
){
$id
=
intval
(
$_GET
['id']);
$db
= model('tool');
$tool
=
$db
->where('id='.
$id
)->find();
if
(!
$tool
)
$this
->error('未找到您要查看的工具');
$ua
=
$_SERVER
[
"HTTP_USER_AGENT"
];
$pathinfo
=
pathinfo
(
$filepath
);
$newfilename
=
$newfilename
.'.'.
$pathinfo
['extension'];
$file
=
fopen
(
$filepath
,
"r"
);
header('Content-Type: application/octet-stream');
header(
"Accept-Ranges: bytes"
);
header(
"Accept-Length: "
.
filesize
(
$filepath
));
if
(preg_match(
"/MSIE/"
,
$ua
)) {
header('Content-Disposition: attachment; filename=
"' . rawurlencode($newfilename) . '"
');
}
else
if
(preg_match(
"/Firefox/"
,
$ua
)) {
header('Content-Disposition: attachment; filename*=
"utf8\'\'' . $newfilename . '"
');
}
else
{
header('Content-Disposition: attachment; filename=
"' . rawurlencode($newfilename) . '"
');
}
echo
fread
(
$file
,
filesize
(
$filepath
));
fclose(
$file
);
}