<?php
$file_name
=
"2.jpg"
;
define(
"SPATH"
,
"/php/image/"
);
$file_sub_path
=
$_SERVER
[
'DOCUMENT_ROOT'
];
$file_path
=
$file_sub_path
.SPATH.
$file_name
;
if
(!
file_exists
(
$file_path
)){
echo
"该文件不存在"
;
return
;
}
$fp
=
fopen
(
$file_path
,
"r"
);
$file_size
=
filesize
(
$file_path
);
header(
"Content-type:application/octet-stream"
);
header(
"Accept-Ranges:bytes"
);
header(
"Accept-Length:"
.
$file_size
);
header(
"Content-Disposition:attachment;filename="
.
$file_name
);
$buffer
=1024;
$file_count
=0;
while
(!
feof
(
$fp
) &&
$file_count
<
$file_size
){
$file_con
=
fread
(
$fp
,
$buffer
);
$file_count
+=
$buffer
;
echo
$file_con
;
}
fclose(
$fp
);
?>