2012-10-04 8 views
0

다음 스 니펫은 "http://pdfx.cs.man.ac.uk/usage"입니다. 이 위대한 도구와 그것은 PDF로 과학 논문을 XML로 변환합니다.유닉스 커맨드 라인 CURL PHP CURL

curl --data-binary @"/path/to/my.pdf" 
    -H "Content-Type: application/pdf" 
    -L "http://pdfx.cs.man.ac.uk" 

이 코드는 유닉스 명령 줄 코드이므로 PHP 버전을 원합니다. 나는 시도했다

$pdfFile = fopen('jucs_18_05_0623_0649_hasan.pdf', 'r'); 
$fileSize = filesize ('jucs_18_05_0623_0649_hasan.pdf'); 
$url="http://pdfx.cs.man.ac.uk"; 
$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 
curl_setopt($ch, CURLOPT_TIMEOUT, 100); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_PUT, true); 
curl_setopt($ch, CURLOPT_INFILE, $pdfFile); 
curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 

$fp = fopen("test.xml", "w"); 
curl_setopt($ch, CURLOPT_FILE, $fp); 

if (! $res = curl_exec($ch)) 
    echo "Error: ".curl_error($ch); 
else { 
    echo "Success"; 
} 
curl_close($ch); 

문제는 test.xml의 출력은 제공된 아티클의 xml 버전을 변환하지 않고 색인 파일 html 코드입니다.

사전

답변

1

에 ... 당신의 전문가의 의견을

덕분에 대기가 필요하지 넣어. 콘텐츠 길이가 필요합니다.

<?php 
$pdfFile = fopen('1.pdf', 'r'); 
$fileSize = filesize ('1.pdf'); 
$url="http://pdfx.cs.man.ac.uk"; 
$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 
curl_setopt($ch, CURLOPT_TIMEOUT, 100); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/pdf","Content-length: ".$fileSize)); 
curl_setopt($ch, CURLOPT_INFILE, $pdfFile); 
curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 

$fp = fopen("test.xml", "w"); 
curl_setopt($ch, CURLOPT_FILE, $fp); 

if (! $res = curl_exec($ch)) 
    echo "Error: ".curl_error($ch); 
else { 
    echo "Success"; 
} 
curl_close($ch); 
?> 
+0

대단히 감사합니다. – Shahid