国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 PHP download breakpoint resume

PHP download breakpoint resume

Nov 09, 2016 pm 02:59 PM

<?php 
/*
 * PHP下載斷點(diǎn)續(xù)傳
 */
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));//獲取文件擴(kuò)展名 
       
    //根據(jù)擴(kuò)展名 指出輸出瀏覽器格式 
    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"; 
    } 
       
    //Begin writing headers 
    header("Cache-Control:"); 
    header("Cache-Control: public"); 
       
    //設(shè)置輸出瀏覽器格式 
    header("Content-Type: $ctype"); 
    if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], "MSIE")) {//如果是IE瀏覽器 
        # 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(&#39;/\./&#39;, &#39;%2e&#39;, $filename, substr_count($filename, &#39;.&#39;) - 1); 
        header("Content-Disposition: attachment; filename=\"$iefilename\""); 
    } else { 
        header("Content-Disposition: attachment; filename=\"$filename\""); 
    } 
    header("Accept-Ranges: bytes"); 
       
    $size=filesize($file); 
    //如果有$_SERVER[&#39;HTTP_RANGE&#39;]參數(shù) 
    if(isset($_SERVER[&#39;HTTP_RANGE&#39;])) { 
/*   --------------------------- 
   Range頭域   Range頭域可以請求實(shí)體的一個(gè)或者多個(gè)子范圍。例如,   表示頭500個(gè)字節(jié):bytes=0-499   表示第二個(gè)500字節(jié):bytes=500-999   表示最后500個(gè)字節(jié):bytes=-500   表示500字節(jié)以后的范圍:bytes=500-   第一個(gè)和最后一個(gè)字節(jié):bytes=0-0,-1   同時(shí)指定幾個(gè)范圍:bytes=500-600,601-999   但是服務(wù)器可以忽略此請求頭,如果無條件GET包含Range請求頭,響應(yīng)會以狀態(tài)碼206(PartialContent)返回而不是以200 (OK)。 
   ---------------------------*/
  
     
// 斷點(diǎn)后再次連接 $_SERVER[&#39;HTTP_RANGE&#39;] 的值 bytes=4390912- 
     
        list($a, $range)=explode("=",$_SERVER[&#39;HTTP_RANGE&#39;]); 
   //if yes, download missing part 
        str_replace($range, "-", $range);//這句干什么的呢。。。。 
   $size2=$size-1;//文件總字節(jié)數(shù) 
        $new_length=$size2-$range;//獲取下次下載的長度 
        header("HTTP/1.1 206 Partial Content"); 
        header("Content-Length: $new_length");//輸入總長 
        header("Content-Range: bytes $range$size2/$size");//Content-Range: bytes 4908618-4988927/4988928   95%的時(shí)候 
    } else {//第一次連接 
        $size2=$size-1; 
        header("Content-Range: bytes 0-$size2/$size"); //Content-Range: bytes 0-4988927/4988928 
        header("Content-Length: ".$size);//輸出總長 
    } 
    //打開文件 
    $fp=fopen("$file","rb"); 
    //設(shè)置指針位置 
    fseek($fp,$range); 
    //虛幻輸出 
    while(!feof($fp)){ 
        //設(shè)置文件最長執(zhí)行時(shí)間 
        set_time_limit(0); 
        print(fread($fp,1024*8));//輸出文件 
        flush();//輸出緩沖 
        ob_flush(); 
    } 
    fclose($fp); 
    exit; 
} 
  
  
dl_file_resume("1.zip");//同級目錄的1.zip 文件 
  
  
  
  
//---------------------------------------
  
//不支持?jǐn)帱c(diǎn)續(xù)傳的文件下載。 
  
//---------------------------------------
  
   
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("文件不存在!"); 
   } 
} 
?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)