欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于php支持分塊與斷點(diǎn)續(xù)傳文件下載功能代碼

 更新時(shí)間:2014年05月09日 09:40:19   作者:  
一篇關(guān)于php流下載,就是可以支持分塊與斷點(diǎn)續(xù)傳文件下載,有需要的朋友可以看看
本文章要介紹了這篇文章是一篇關(guān)于php流下載,就是可以支持分塊與斷點(diǎn)續(xù)傳文件下載,有需要的朋友可以看看。代碼如下
復(fù)制代碼 代碼如下:

$dowmFile = dirname ( __FILE__ ) . ‘/Nokia – Always Here.mp3′; //要下載的文件,絕對(duì)或相對(duì)
$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 使用openssl 擴(kuò)展實(shí)現(xiàn)公鑰加密的方法

    PHP 使用openssl 擴(kuò)展實(shí)現(xiàn)公鑰加密的方法

    下面小編就為大家分享一篇PHP 使用openssl 擴(kuò)展實(shí)現(xiàn)公鑰加密的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • php自動(dòng)獲取關(guān)鍵字的方法

    php自動(dòng)獲取關(guān)鍵字的方法

    這篇文章主要介紹了php自動(dòng)獲取關(guān)鍵字的方法,通過(guò)自定義函數(shù)tiqukeyword實(shí)現(xiàn)關(guān)鍵字的自動(dòng)獲取功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • Windows下的PHP5.0詳解

    Windows下的PHP5.0詳解

    Windows下的PHP5.0詳解...
    2006-11-11
  • JS操作XML中DTD介紹及使用方法分析

    JS操作XML中DTD介紹及使用方法分析

    這篇文章主要介紹了JS操作XML中DTD介紹及使用方法,結(jié)合實(shí)例形式分析了DTD概念、原理及校驗(yàn)xml文檔的相關(guān)操作技巧,需要的朋友可以參考下
    2019-07-07
  • php使用yield對(duì)性能提升的測(cè)試實(shí)例分析

    php使用yield對(duì)性能提升的測(cè)試實(shí)例分析

    這篇文章主要介紹了php使用yield對(duì)性能提升的測(cè)試,結(jié)合具體實(shí)例形式對(duì)比分析了php使用yield及常規(guī)操作的運(yùn)算耗時(shí)與內(nèi)存占用情況,測(cè)試了yield對(duì)性能的提升大小,需要的朋友可以參考下
    2019-09-09
  • laravel8中常用路由的使用詳解

    laravel8中常用路由的使用詳解

    在Laravel?8中,路由定義了應(yīng)用程序中接受請(qǐng)求的方式,它們定義了URL和相應(yīng)的控制器方法之間的映射關(guān)系,下面我們就來(lái)學(xué)習(xí)一下laravel8中常用路由的使用吧
    2023-11-11
  • Pear DB 新手入門(mén)指南教程

    Pear DB 新手入門(mén)指南教程

    通過(guò) Pear DB可以從查詢(xún)結(jié)果獲得更多有用的數(shù)據(jù)信息 。這些方法有: numRows(): 通過(guò)一個(gè)"SELECT" 查詢(xún)返回所有數(shù)據(jù)的數(shù)量。
    2008-11-11
  • PHP關(guān)于IE下的iframe跨域?qū)е聅ession丟失問(wèn)題解決方法

    PHP關(guān)于IE下的iframe跨域?qū)е聅ession丟失問(wèn)題解決方法

    一個(gè)登錄頁(yè)面,被別的網(wǎng)站用iframe嵌進(jìn)去后,死活無(wú)法登錄(只在IE中存在這種情況)。主要是session無(wú)法被保存的問(wèn)題,下面把個(gè)人的解決過(guò)程分享個(gè)大家
    2013-10-10
  • 解析PHP獲取當(dāng)前網(wǎng)址及域名的實(shí)現(xiàn)代碼

    解析PHP獲取當(dāng)前網(wǎng)址及域名的實(shí)現(xiàn)代碼

    本篇文章是對(duì)PHP獲取當(dāng)前網(wǎng)址及域名的代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • php 如何獲取文件的后綴名

    php 如何獲取文件的后綴名

    本文給大家匯總了幾種使用PHP實(shí)現(xiàn)獲取文件的后綴名的方法,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下
    2016-06-06

最新評(píng)論