簡體   English   中英

我如何在php中使用curl命令?

[英]how i can use this curl command in php?

我正在嘗試在網站端口80上發送用戶輸入的文件,並使用以下curl命令發送此文件以在服務器上執行:

curl -v --form input=@./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發送文件是否會發生問題?

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

// 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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM