public function download()
{
$famlePath = $_GET[‘resum’];
f
i
l
e
d
i
r
=
R
O
O
T
P
A
T
H
.
′
p
u
b
l
i
c
′
.
D
S
.
′
u
p
l
o
a
d
s
′
.
′
/
′
.
"
file_dir = ROOT_PATH . 'public' . DS . 'uploads' . '/' . "
filedir=ROOTPATH.′public′.DS.′uploads′.′/′."famlePath";
// 下载文件存放目录
// 检查文件是否存在
if (! file_exists($file_dir) ) {
$this->error(‘文件未找到’);
}else{
// 打开文件
f
i
l
e
1
=
f
o
p
e
n
(
file1 = fopen(
file1=fopen(file_dir, “r”);
// 输入文件标签
Header(“Content-type: application/octet-stream”);
Header(“Accept-Ranges: bytes”);
Header(“Accept-Length:”.filesize($file_dir));
Header(“Content-Disposition: attachment;filename=” .
f
i
l
e
d
i
r
)
;
o
b
c
l
e
a
n
(
)
;
/
/
重点!!!
f
l
u
s
h
(
)
;
/
/
重点!!!!可以清除文件中多余的路径名以及解决乱码的问题:
/
/
输出文件内容
/
/
读取文件内容并直接输出到浏览器
e
c
h
o
f
r
e
a
d
(
file_dir); ob_clean(); // 重点!!! flush(); // 重点!!!!可以清除文件中多余的路径名以及解决乱码的问题: //输出文件内容 //读取文件内容并直接输出到浏览器 echo fread(
filedir);obclean();//重点!!!flush();//重点!!!!可以清除文件中多余的路径名以及解决乱码的问题://输出文件内容//读取文件内容并直接输出到浏览器echofread(file1, filesize(
f
i
l
e
d
i
r
)
)
;
f
c
l
o
s
e
(
file_dir)); fclose(
filedir));fclose(file1);
exit();
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交