2016-11-10 11 views
0

PHP 코드를 개발하고 클라이언트가 얼마나 많은 데이터를 다운로드했는지 계산합니다. 누군가 브라우저에서 직접 내 파일을 요청하면 내 코드가 제대로 작동합니다. 그러나 누군가가 ''다운 타임 ''과 같은 모질라 확장을 설치 한 다음 해당 확장으로 URL을 요청하면 파일 URL을 4 번 요청하여 다운로드 한 데이터를 4 번받습니다. 이 문제를 어떻게 해결할 수 있습니까? 사용자가 jDownloader 소프트웨어 또는 소프트웨어를 사용할 때도 마찬가지입니다.Mozilla Extension이 URL 요청이 여러 번 발생하는 이유는 무엇입니까?

여기 내 전체 다운로드 코드 : -

때문에 분할/병렬 다운로드
<?php 

function getMimeType($fileName) 
{ 
    $c_type_default = "application/octet-stream"; 
    $content_types = array(
     "exe" => "application/octet-stream", 
     "zip" => "application/zip", 
     "mp3" => "audio/mpeg", 
     "mpg" => "video/mpeg", 
     "avi" => "video/x-msvideo", 
     "mp4" => "video/mp4", 
    ); 
// echo isset($content_types[pathinfo($fileName, PATHINFO_EXTENSION)]) ? $content_types[pathinfo($fileName, PATHINFO_EXTENSION)] : $c_type_default;  
    return isset($content_types[pathinfo($fileName, PATHINFO_EXTENSION)]) ? $content_types[pathinfo($fileName, PATHINFO_EXTENSION)] : $c_type_default; 
} 
function output_file($file, $name) 
{ 

/* 
This function takes a path to a file to output ($file), the filename that the browser will see ($name) and the MIME type of the file ($mime_type, optional). 
*/ 

//Check the file premission 
if(!is_readable($file)) die('File not found or inaccessible!'); 

$size = filesize($file); 

$name = rawurldecode($name); 

//turn off output buffering to decrease cpu usage 
    @ob_end_clean(); 
    include('../includes/configg.php'); 

    // Start Code For Total Downloaded Data Size by The LoggedIn User 
     $user="select * from $TBusers where id=".$_SESSION['log_id']; 
     $result_user = mysqli_query($conn, $user) ; 
     $row = mysqli_fetch_assoc($result_user); 
     $lastsotrage = $row['down']; 
     $curr_date= $row['curr_date']; 
     $today_date= date('d-m-y'); 
     $daily_downloaded_data= $row['daily_downloaded_data']; 
     if($curr_date != $today_date) 
     { 
       $update_curr_date="update $TBusers set curr_date ='$today_date', daily_downloaded_data =0 where id=".$_SESSION['log_id']; // Set Curr_date by Today Date For check Daily Downloaded Data Limit 

       mysqli_query($conn,$update_curr_date) ; 
       $daily_downloaded_data=0; 
     } 
     /*else 
     { 
      if($daily_downloaded_data>=(20*1024*1024*1024)){   // Check Daily Download Data Limit 20GB Exceed or not 
      header('Location: http://idownload.club/members/download.php'); 
      exit;} 
     }*/ 


// required for IE, otherwise Content-Disposition may be ignored 
if(ini_get('zlib.output_compression')) 
ini_set('zlib.output_compression', 'Off'); 

header('Content-Type: ' . getMimeType($name)); 
header('Content-Disposition: attachment; filename="'.$name.'"'); 
header("Content-Transfer-Encoding: binary"); 
header('Accept-Ranges: bytes'); 

/* The three lines below basically make the 
    download non-cacheable */ 
header("Cache-control: private"); 
header('Pragma: private'); 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 

// multipart-download and download resuming support 
if(isset($_SERVER['HTTP_RANGE'])) 
{ 
    list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2); 
    list($range) = explode(",",$range,2); 
    list($range, $range_end) = explode("-", $range); 
    $range=intval($range); 
    if(!$range_end) { 
     $range_end=$size-1; 
    } else { 
     $range_end=intval($range_end); 
    } 

    $new_length = $range_end-$range+1; 
    header("HTTP/1.1 206 Partial Content"); 
    header("Content-Length: $new_length"); 
    header("Content-Range: bytes $range-$range_end/$size"); 
} else { 
    $new_length=$size; 
    header("Content-Length: ".$size); 
} 

/* Will output the file itself */ 
$chunksize = 1*(1024*1024); //you may want to change this 
$bytes_send = 0; 
if ($file = fopen($file, 'r')) 
{ 
    if(isset($_SERVER['HTTP_RANGE'])) 
    fseek($file, $range); 

    while(!feof($file) && 
     (!connection_aborted()) && 
     ($bytes_send<$new_length) 
     ) 
    { 
     $buffer = fread($file, $chunksize); 
     print($buffer); //echo($buffer); // can also possible 
     flush(); 
     $bytes_send += strlen($buffer); 
    } 
fclose($file); 

      $lastsotrage= $lastsotrage + $size; 
      $daily_downloaded_data+=$size; 
      $sql="update $TBusers set down =". $lastsotrage." where id=".$_SESSION['log_id']; 
      $sql2="update $TBusers set daily_downloaded_data = $daily_downloaded_data where id=".$_SESSION['log_id']; 
      $sql3= "update test set count=count+1 where id=1" ; 
      mysqli_query($conn,$sql) ; 
      mysqli_query($conn,$sql2) ;mysqli_query($conn,$sql3) ; 
      file_put_contents('data.txt', print_r($_SERVER, true), FILE_APPEND); 


} else 
//If no permissiion 
die('Error - can not open file.'); 
//die 
die(); 
} 
//Set the time out 
set_time_limit(0); 



//path to the file 
$file_dir=$_GET['directory']; 
$file_name = str_replace("/", "", $_GET['file']); 
$file_name = str_replace("\\", "", $file_name); 
$file = $file_dir . "/".$file_name; 


//Call the download function with file path,file name and file type 
output_file($file, ''.$file_name.''); 


?> 

답변

0

.

언급 된 확장 프로그램은 브라우저에서 액세스 할 때 전체 콘텐츠가 아닌 콘텐츠 범위를 요청합니다. 이 기능을 사용하면 파일 내용을 동시에 다운로드 할 수 있으며 대부분 짧은 시간 내에 다운로드 할 수 있습니다.

partial contentrange requests에 대해 자세히 알아보십시오. enter image description here

+0

죄송하지만, 자신의 브라우저에서이 작업을 수행하기 위해 내 고객에게 강제 할 수 없기 때문에이 내 문제에 대해 작동되지 않습니다 클라이언트 측에

, 이것은 (명 DownThemAll) 변경 될 수 있습니다. 나는 이것을 PHP 코드로하고 싶다. 그래서 다시 한번보세요. 감사 –