2012-10-09 4 views
0

readfile()을 사용하여 큰 파일 (1.3GB)을 다운로드하는 스크립트가 있습니다.ModX Evo : PHP readfile() 스 니펫?

그냥 스크립트로 .php 페이지를 만들면 정상적으로 작동하지만 스 니펫에 같은 스크립트를 배치하고 페이지에 배치하면 아무 일도 일어나지 않습니다.

ModX가 다운로드를 차단하는 이유는 무엇입니까? 어떤 조언이라도 대단히 감사 할 것입니다!

편집 코드 :

$file = $_SERVER['DOCUMENT_ROOT']."/movie.mov"; 
if (file_exists($file)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.basename($file)); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 
    exit; 
}; 
+0

'header()'가 호출되기 전에'ob_clean();'이 오지 않아야합니까? – Niloct

+0

@Niloct 일 수도 있지만 위의 내용은 PHP 설명서 – MeltingDog

+0

의 예제입니다. Modx 코드 단편은 [출력] (http://rtfm.modx.com/display/revolution20/Snippets#Snippets-SimpleExample) 정보 만 반환 할 수 있습니다. '데이터. 그'flush()'는 범인일지도 모른다. – Niloct

답변

0

Modx가 최대 파일 크기 설정 [최대 업로드 크기 upload_maxsize]을 가지고 있지만, 파일 관리자를위한 것입니다. 나는 그것이 당신의 문제인지 의심 스럽다.

스크립트와 오류 로그를 봅시다.

UPDATE는 ~ 잘 작동 [사소한 변경의 부부와 함께] 당신의 작은 조각을 테스트했다. $ modx-> 설정 [ 'base_path를']를 사용하여

$base_path = $modx->config['base_path']; 

$movie = 'frankenweenie-mrwhiskers_r640s.mov'; 

$file = $base_path.$movie; 


if (file_exists($file)) { 

    echo 'file exists '.filesize($file); 

    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.basename($file)); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 

    return true; 

}else{ 

    echo 'file does not exist'; 

    return false; 

} 

당신의 문제가 아니다, 서버뿐만 아니라 바르, 그냥 좋은 습관 사용했다. return true/false modx는 true, false 또는 $ output ...인지 여부를 결정하기 위해 미리보기가 필요하다고 생각합니다.

PHP 설정을 살펴보기 시작하면 아마도 메모리 제한이 문제 일 수 있다고 생각합니다. php docs &에서 size만큼의 파일을 읽을 수있는 충분한 메모리가 필요한지 확인하십시오. [ '크기가 중요하지 않습니다'라고 표시하더라도]

스크립트 자체에 오류 로깅을 활성화하려면 & 서버 오류 로그를 확인하십시오.

작은 파일에서도 작동합니까? 그럼 여기 좀 봐 : PHP readfile() and large downloads

행운을 빌어 요!

+0

오류 로그에 아무것도 추가하지 않았습니다 ... – MeltingDog