<?php
function
dl_file_resume(
$file
){
if
(!
is_file
(
$file
)) {
die
(
"<b>404 File not found!</b>"
); }
$len
=
filesize
(
$file
);
$filename
=
basename
(
$file
);
$file_extension
=
strtolower
(
substr
(
strrchr
(
$filename
,
"."
),1));
switch
(
$file_extension
) {
case
"exe"
:
$ctype
=
"application/octet-stream"
;
break
;
case
"zip"
:
$ctype
=
"application/zip"
;
break
;
case
"mp3"
:
$ctype
=
"audio/mpeg"
;
break
;
case
"mpg"
:
$ctype
=
"video/mpeg"
;
break
;
case
"avi"
:
$ctype
=
"video/x-msvideo"
;
break
;
default
:
$ctype
=
"application/force-download"
;
}
header(
"Cache-Control:"
);
header(
"Cache-Control: public"
);
header(
"Content-Type: $ctype"
);
if
(
strstr
(
$_SERVER
['HTTP_USER_AGENT'],
"MSIE"
)) {
# workaround
for
IE filename bug with multiple periods / multiple dots in filename
# that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
$iefilename
= preg_replace('/\./', '%2e',
$filename
, substr_count(
$filename
, '.') - 1);
header(
"Content-Disposition: attachment; filename=\"$iefilename\""
);
}
else
{
header(
"Content-Disposition: attachment; filename=\"$filename\""
);
}
header(
"Accept-Ranges: bytes"
);
$size
=
filesize
(
$file
);
if
(isset(
$_SERVER
['HTTP_RANGE'])) {
list(
$a
,
$range
)=
explode
(
"="
,
$_SERVER
['HTTP_RANGE']);
str_replace
(
$range
,
"-"
,
$range
);
$size2
=
$size
-1;
$new_length
=
$size2
-
$range
;
header(
"HTTP/1.1 206 Partial Content"
);
header(
"Content-Length: $new_length"
);
header(
"Content-Range: bytes $range$size2/$size"
);
}
else
{
$size2
=
$size
-1;
header(
"Content-Range: bytes 0-$size2/$size"
);
header(
"Content-Length: "
.
$size
);
}
$fp
=
fopen
(
"$file"
,
"rb"
);
fseek
(
$fp
,
$range
);
while
(!
feof
(
$fp
)){
set_time_limit(0);
print
(
fread
(
$fp
,1024*8));
flush
();
ob_flush();
}
fclose(
$fp
);
exit
;
}
dl_file_resume(
"1.zip"
);
downFile(
"1.zip"
);
function
downFile(
$sFilePath
)
{
if
(
file_exists
(
$sFilePath
)){
$aFilePath
=
explode
(
"/"
,
str_replace
(
"\\"
,
"/"
,
$sFilePath
),
$sFilePath
);
$sFileName
=
$aFilePath
[
count
(
$aFilePath
)-1];
$nFileSize
=
filesize
(
$sFilePath
);
header (
"Content-Disposition: attachment; filename="
.
$sFileName
);
header (
"Content-Length: "
.
$nFileSize
);
header (
"Content-type: application/octet-stream"
);
readfile(
$sFilePath
);
}
else
{
echo
(
"文件不存在!"
);
}
}
?>