将此curl命令转换为php curl
我正试图编写一个php文件来使用docker容器中的微型服务,该容器将html转换为pdf 我可以这样做,没有问题:将此curl命令转换为php curl,php,docker,curl,Php,Docker,Curl,我正试图编写一个php文件来使用docker容器中的微型服务,该容器将html转换为pdf 我可以这样做,没有问题: curl -vv -F --output 'file=@/home/user/Documents/contract.html' http://0.0.0.0:32768/ -o /home/user/contract.pdf 现在我试图在php文件中“翻译”这个命令,但这是我第一次在php中使用curl //Initialise the cURL var $ch
curl -vv -F --output 'file=@/home/user/Documents/contract.html' http://0.0.0.0:32768/ -o /home/user/contract.pdf
现在我试图在php文件中“翻译”这个命令,但这是我第一次在php中使用curl
//Initialise the cURL var
$ch = curl_init();
//Get the response from cURL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the Url
curl_setopt($ch, CURLOPT_URL, 'http://0.0.0.0:32768/');
//Create a POST array with the file in it
$postData = array(
'testData' => '@/home/user/Documents/contract.html',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// Execute the request
$response = curl_exec($ch);
var_dump($response);
我缺少命令的
-o
选项,以及将html文件转换为pdf后应获取的文件的路径和名称。我想您正在查找CURLOPT\u文件
CULLOPT_文件传输应写入的文件。默认设置为标准输出(浏览器窗口)
()我想你在找
CURLOPT\u文件
CULLOPT_文件传输应写入的文件。默认设置为标准输出(浏览器窗口)
()
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "curl%20-vv%20-F%20--output%20'file=@/home/user/Documents/contract.html'%20http://0.0.0.0:32768/%20-o%20/home/user/contract.pdf%0A%0A",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;