2012-01-28 10 views
3

여기에이 코드가 있습니다. 그러나 사용자가 다운로드 할 수있는 속도를 제한하려면 어떻게해야합니까?PHP로 다운로드 속도 제한하기

header("Content-type: application/force-download"); 
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-length: ".filesize("uploads/$filename")); 
    header("Content-disposition: attachment; filename=\"$origname"); 
    readfile("uploads/$filename"); 

감사!

이것은 내가 시도한 것입니다.

$download_rate = 100; 

$ origname = get_file_name ($ file [0]);

header("Content-type: application/force-download"); 
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-length: ".filesize("uploads/$filename")); 
    header("Content-disposition: attachment; filename=\'$origname'"); 

    $local_file = "uploads/$origname"; 

// 플러시 콘텐츠 flush();

// open file stream 
$file = fopen($local_file, "r"); 

while (!feof($file)) { 

    // send the current file part to the browser 
    print fread($file, round($download_rate * 1024)); 

    // flush the content to the browser 
    flush(); 

    // sleep one second 
    sleep(1); 
} 

// close file stream 
fclose($file); 

왜 작동하지 않습니까? 그런 다음 다른 곳에 문제가있을 수 있습니다 무엇을 제안 @mugur 시도한 경우

답변

1

을하는 데 도움이됩니다.

내가 추측;

헤더 (; $의 origname ""파일 이름 = \ 첨부 파일 내용 - 처리 : ") 당신의 조각의 예를 들어 당신이 누락 탈출 따옴표가있어 보인다 해야한다 :

헤더 것은 ("내용 - 처리 : 첨부 파일, 파일 이름 = \"$의 origname의 \ ""); 당신의 동안의 FREAD에서

1
+0

그래, 나는이 하나를 읽었지만, 나는 그것을 통합하는 방법이 정말로 필요하다. – HarryBeasant

+2

음, 무엇을 시도 했습니까? 어떻게 실패 했는가? 이것은 좋은 출발점처럼 보이므로 모든 사람에게 이미 한 일을 다시하도록 요청하지 마십시오. – Hamish

+2

오류가 발생합니까? 더 빨리 다운로드하거나 어떻게 실패합니까? – Mike

0

, 그냥 바이트와 t를 계산 imestamps. 그런 다음 usleep을 사용하여 작은 일시 중지를 추가하십시오.

관련 문제