2012-06-08 4 views
1

나는 변수로 pdf 파일의 내용을 좀하고 싶습니다. 나는 ("file.pdf")를PHP, PDF 파일에 null을 반환 file_get_contents()는

file_get_contents를 사용하여

을이 작업을 수행하려고하지만 NULL을 반환합니다. 예를 들어 .jpg 파일과 동일하게 작동하는 경우 작동합니다. 이 문제를 어떻게 극복 할 수 있을지 생각해보십시오. 다른 방법이 있습니까? 미리 감사드립니다!

편집 :

서비스 코드 :

<?php 

function sendAttachment($msg){ 
$responsePayloadString = <<<XML 
    <payload:receiveReport xmlns:payload="http://wso2.org/wsfphp/samples/mtom"> 
     <payload:reports> 
      <payload:report> 
       <payload:content xmlmime:contentType="application/pdf" xmlns:xmlmime="http://www.w3.org/2004/06/xmlmime"> 
        <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:report1"></xop:Include> 
       </payload:content> 
      </payload:report> 
     </payload:reports> 
    </payload:receiveReport> 
XML; 
$report1 = file_get_contents("samplePDF.pdf"); 

$responseMessage = new WSMessage($responsePayloadString, 
     array("attachments" => array("report1" => $report1), 
       "useWSA" => TRUE)); 
return $responseMessage;  
} 

$operations = array("receiveReport" => "sendAttachment"); 

$service = new WSService(array("operations" => $operations, 
              "requestXOP" => TRUE, 
              "useMTOM" => TRUE)); 

$service->reply(); 

?> 

클라이언트 코드 :

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 

/******* FirePHP Debug *******/ 
require_once('../FirePHPCore/FirePHP.class.php'); 
ob_start(); 
$firephp = FirePHP::getInstance(true); 
/******* FirePHP Debug *******/ 

$requestPayloadString = <<<XML 
<receiveReport></receiveReport> 

XML;

try { 
$client = new WSClient(
    array("to" => "http://localhost/ReportDL/ReportService.php", 
      "useMTOM" => TRUE, 
      "responseXOP" => TRUE, 
      "useWSA" => TRUE)); 

$requestMessage = new WSMessage($requestPayloadString);      
$responseMessage = $client->request($requestMessage); 

$cid2stringMap = $responseMessage->attachments; 
$cid2contentMap = $responseMessage->cid2contentType; 

if($cid2stringMap && $cid2contentMap){ 
    foreach($cid2stringMap as $i=>$value){ 
     $f = $cid2stringMap[$i]; 
     $contentType = $cid2contentMap[$i]; 

     $firephp->log($f, "pdf");  //DEBUG 

    } 
}else{ 
    printf("attachments not received "); 
} 

} catch (Exception $e) { 

if ($e instanceof WSFault) { 
    printf("Soap Fault: %s\n", $e->Reason); 
} else { 
    printf("Message = %s\n",$e->getMessage()); 
} 
} 

?> 

Edit2가 : 파일을 읽을 경우

string '%PDF-1.5 
%âãÏÓ 
2 0 obj 
<</Length 285/Filter/FlateDecode>>stream 
xœ’_KÃ0Åßó)Ä{“4i|S¨‚ÓÀžµKiçÚ­0¿½i;ëýƒ#ÐÐÃýœž¦dwŽI 
&ÒàV,qlÁJfŒ�%hCåÙ’­;YǪÕrÿÎÿêeã|}[email protected]\Æ0,‹<ÌXäE¯6OW°‹‡z 
ñÑ 
Z¸}¼t]®æ$ä’Õð³ToGÞ!5¾í»R ›4Ù<)¤:•&ž@©ù¸v’4®ƒžB®gÁ6è49X»P‚[email protected]ÌíPñîÝÃҿ“ß|V;Hö/Å&÷Ðw?f I.MHq²Mö>­w~5k$‘8Šq£ç:õÛmVçù?òi©ý'Ó-Í^$eNðÿ\¥sá6ø(¼`ßè¿Á÷ 
endstream 
endobj 
6 0 obj 
<</Type/Catalog/PageMode/UseNone/Pages 3 0 R>> 
endobj 
7 0 obj 
<</Creator(BIRT Report Engine 2.6.0 using iText version unknown.)/Producer('... (length=1231) 
+3

는'file.pdf' 존재 하는가? 'file_get_contents()'를 통해 읽는 웹 서버에 읽기 권한이 있습니까? –

+0

'file_exists ("file.pdf")'의 출력을 말하고 저희에게 알려주십시오! –

+0

그 단일 코드는 문맥을 벗어난 것처럼 보입니다. 어떻게 사용하는지 보여줄 수 있습니까? – Repox

답변

1

file_get_contents()FALSE을 반환해야는 - 그렇지 않으면 파일의 내용을 포함하는 문자열을 반환합니다.

문제는 다른 곳에서 발생해야합니다. 코드가 절차 상으로 var_dump()으로 디버깅되기 시작하여 데이터가 손실 된 곳을 찾으십시오.