2016-06-21 3 views
1

PHP 서버 스크립트에 간단한 XMLHttpRequest가 있습니다. 코드 서버 스크립트의XMLHttpRequest로 큰 pdf 파일을 읽을 수 없습니다.

fxhr.onload = function (data) { 
    //console.log(JSON.parse(data.target.response)); 
    var string = JSON.parse(data.target.response).data.content; 
    console.log(JSON.parse(data.target.response)); 
    DEFAULT_URL = convertDataURIToBinary(string); 

    var config = getViewerConfiguration(); 
    window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication; 
    pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config); 
    }; 
    fxhr.open('POST', window.location.pathname + 'content'); 

가 :

 public function execute() 
{ 
    $productModel = new shopProductModel(); 
    $bookModel = new shopEbooksPluginItemModel(); 
    $item = $productModel->getByField('url', waRequest::param('product_code')); 
    $bookFile = $bookModel->getByField(array(
    'product_id' => $item['id'], 
    'book_type' => waRequest::param('reader_state') 
), false); 
    $content = @file_get_contents($this->getBookFullPath($bookFile)); 

    $this->response = array('content' => $this->getBaseEncodedFile()); 
} 

private function getBookFullPath($bookFileRow) 
{ 
    return $bookFileRow['file_path'] . $bookFileRow['file_name']; 
} 

private function getBaseEncodedFile($content) 
{ 
    return 'data:application/pdf;base64,' . base64_encode($content); 
} 

내가 작은 PDF 파일을 읽을려고하면 그것은 작품 좋은,하지만 난 40메가바이트 pdf 파일 서버 응답을 읽어보십시오 경우에만 "데이터가 : 응용 프로그램/PDF로; base64로 , ". file_exists가 true를 반환합니다.

+0

'error_log'에 도움이 될만한 메시지가 있습니까? –

+0

어쩌면 내가 시도해보십시오 –

답변

0

PHP에는 php.ini 파일에 몇 가지 설정이있어서 문제를 일으킬 수 있습니다.

memory_limit - 이것은 거의 확실하게 문제입니다. PHP는 모든 데이터를 처리하기 위해 메모리에로드해야합니다. 처리 할 것으로 예상되는 가장 큰 크기의 파일보다이 값을 50 % 더 늘려보십시오.

max_execution_time - 스크립트가 모든 데이터를 처리하는 데 오랜 시간이 걸리면 죽게됩니다. 이 값을 늘리십시오.

스크립트가 대용량 데이터를 처리 할 수 ​​있도록 종종 php.ini에서 이러한 제한을 수정해야했습니다.

+0

'memory_limit 128' 'max_execution_time 180' 즉각 null을 반환합니다. –

+0

'memory_limit 128'은 128 ** 바이트 **를 의미합니다. 'memory_limit 128M'을 128 ** 메가 바이트로 사용해보십시오 ** –

+0

yes 128M now php.ini –

관련 문제