真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

如何編寫php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼-創(chuàng)新互聯(lián)

這篇文章主要介紹“如何編寫php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼”,在日常操作中,相信很多人在如何編寫php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何編寫php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

我們一直強(qiáng)調(diào)網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作對于企業(yè)的重要性,如果您也覺得重要,那么就需要我們慎重對待,選擇一個(gè)安全靠譜的網(wǎng)站建設(shè)公司,企業(yè)網(wǎng)站我們建議是要么不做,要么就做好,讓網(wǎng)站能真正成為企業(yè)發(fā)展過程中的有力推手。專業(yè)網(wǎng)站制作公司不一定是大公司,創(chuàng)新互聯(lián)公司作為專業(yè)的網(wǎng)絡(luò)公司選擇我們就是放心。

復(fù)制代碼 代碼如下:

$dowmFile = dirname ( __FILE__ ) . ‘/Nokia – Always Here.mp3′; //要下載的文件,絕對或相對
$dowmName = ‘Nokia – Always Here.mp3′;
ob_start ();
getlocalfile ( $dowmFile, $dowmName );
flush ();
ob_flush ();
function getlocalfile($fname, $filename = ”) {
$fsize = filesize ( $fname );
header ( ‘Cache-Control: public' );
header ( ‘Pragma: public' );
header ( ‘Accept-Ranges: bytes' );
header ( ‘Connection: close' );
header ( ‘Content-Type: ‘ . MIMEType ( $fname ) );
//header(‘Content-Type: application/octet-stream');
if (isset ( $filename {0} )) {
header ( ‘Content-Disposition: attachment;filename=' . $filename );
}
if ($fp = @fopen ( $fname, ‘rb' )) {
$start = 0;
$end = $fsize;
$isRange = isset ( $_SERVER ['HTTP_RANGE'] ) && ($_SERVER ['HTTP_RANGE'] != ”);
if ($isRange) {
preg_match ( ‘/^bytes=([0-9]*)-([0-9]*)$/i', $_SERVER ['HTTP_RANGE'], $match );
$start = $match [1];
$end = $match [2];
$isset_start = isset ( $start {0} );
$isset_end = isset ( $end {0} );
if ($isset_start && $isset_end) {
//分塊下載
if ($start >= $fsize || $start < 0 || $start > $end) {
$start = 0;
$end = $fsize;
} else if ($end >= $fsize) {
$end = $fsize – $start;
} else {
$end -= $start – 1;
}
} else if ($isset_start && ! $isset_end) {
//指定位置到結(jié)束
if ($start >= $fsize || $start < 0) {
$start = 0;
$end = $fsize;
} else {
$end = $fsize – $start;
}
} else if (! $isset_start && $isset_end) {
//最后n個(gè)字節(jié)
$end = $end > $fsize ? $fsize : $end;
$start = $fsize – $end;
} else {
$start = 0;
$end = $fsize;
}
}
if ($isRange) {
fseek ( $fp, $start );
header ( ‘HTTP/1.1 206 Partial Content' );
header ( ‘Content-Length: ‘ . $end );
header ( ‘Content-Ranges: bytes ‘ . $start . ‘-' . ($end + $start – 1) . ‘/' . $fsize );
} else {
header ( ‘Content-Length: ‘ . $fsize );
}
if (function_exists ( ‘fpassthru' ) && ($end + $start) == $fsize) {
fpassthru ( $fp );
} else {
echo fread ( $fp, $end );
}
} else {
header ( ‘Content-Length: ‘ . $fsize );
readfile ( $fname );
}
//@header(“Content-Type: “.mime_content_type($fname));
}
function MIMEType($fname) {
$fileSuffix = strtolower ( substr ( $fname, strrpos ( $fname, ‘.' ) + 1 ) );
switch ($fileSuffix) {
case ‘a(chǎn)vi' :
return ‘video/msvideo';
case ‘wmv' :
return ‘video/x-ms-wmv';
case ‘txt' :
return ‘text/plain';
case ‘htm' :
case ‘html' :
case ‘php' :
return ‘text/html';
case ‘css' :
return ‘text/css';
case ‘js' :
return ‘a(chǎn)pplication/javascript';
case ‘json' :
case ‘xml' :
case ‘zip' :
case ‘pdf' :
case ‘rtf' :
case ‘tar' :
return ‘a(chǎn)pplication/' . $fileSuffix;
case ‘swf' :
return ‘a(chǎn)pplication/x-shockwave-flash';
case ‘flv' :
return ‘video/x-flv';
case ‘jpe' :
case ‘jpg' :
return ‘image/jpeg';
case ‘jpeg' :
case ‘png' :
case ‘gif' :
case ‘bmp' :
case ‘tiff' :
return ‘image/' . $fileSuffix;
case ‘ico' :
return ‘image/vnd.microsoft.icon';
case ‘tif' :
return ‘image/tiff';
case ‘svg' :
case ‘svgz' :
return ‘image/svg+xml';
case ‘rar' :
return ‘a(chǎn)pplication/x-rar-compressed';
case ‘exe' :
case ‘msi' :
return ‘a(chǎn)pplication/x-msdownload';
case ‘cab' :
return ‘a(chǎn)pplication/vnd.ms-cab-compressed';
case ‘a(chǎn)if' :
return ‘a(chǎn)udio/aiff';
case ‘mpg' :
case ‘mpe' :
case ‘mp3′ :
return ‘a(chǎn)udio/mpeg';
case ‘mpeg' :
case ‘wav' :
case ‘a(chǎn)iff' :
return ‘a(chǎn)udio/' . $fileSuffix;
case ‘qt' :
case ‘mov' :
return ‘video/quicktime';
case ‘psd' :
return ‘image/vnd.adobe.photoshop';
case ‘a(chǎn)i' :
case ‘eps' :
case ‘ps' :
return ‘a(chǎn)pplication/postscript';
case ‘doc' :
case ‘docx' :
return ‘a(chǎn)pplication/msword';
case ‘xls' :
case ‘xlt' :
case ‘xlm' :
case ‘xld' :
case ‘xla' :
case ‘xlc' :
case ‘xlw' :
case ‘xll' :
return ‘a(chǎn)pplication/vnd.ms-excel';
case ‘ppt' :
case ‘pps' :
return ‘a(chǎn)pplication/vnd.ms-powerpoint';
case ‘odt' :
return ‘a(chǎn)pplication/vnd.oasis.opendocument.text';
case ‘ods' :
return ‘a(chǎn)pplication/vnd.oasis.opendocument.spreadsheet';
default :
if (function_exists ( ‘mime_content_type' )) {
$fileSuffix = mime_content_type ( $filename );
} else {
$fileSuffix = ‘a(chǎn)pplication/octet-stream';
}
return $fileSuffix;
break;
}
}


到此,關(guān)于“如何編寫php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!


文章名稱:如何編寫php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://weahome.cn/article/iisdo.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部