2017-02-21 54 views
0

我試圖發送從用戶輸入自己的網站端口80上的一個文件,並使用該curl命令將此文件發送到服務器上執行:我如何在PHP中使用這個curl命令?

curl -v --form [email protected]/file.pdf localhost:8080/processHeaderDocument -o ./file.xml 

我嘗試這樣做,但它是不迴應任何東西

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

curl_exec($ch); 

curl_close($ch); 

如何在php中使用此命令?通過端口80發送文件到8080會發生問題嗎?

回答

0

試試下面的代碼希望這可以解決你的問題。

// initialise the curl request 
$request = curl_init('http://example.com/'); 

// send a file 
curl_setopt($request, CURLOPT_POST, true); 
curl_setopt(
    $request, 
    CURLOPT_POSTFIELDS, 
    array(
     'file' => '@' . realpath('example.txt') 
    )); 

// output the response 
curl_setopt($request, CURLOPT_RETURNTRANSFER, true); 
echo curl_exec($request); 

// close the session 
curl_close($request); 

以下是鏈接。 http://code.stephenmorley.org/php/sending-files-using-curl/

+0

我嘗試此代碼,似乎服務器無法找到與此錯誤 [錯誤] org.grobid.service.process.GrobidRestProcessFiles文件路徑:一個意外的異常:顯示java.lang.NullPointerException [錯誤] org.grobid.core.utilities.IOUtilities:刪除臨時文件時出錯: java.lang.NullPointerException –