命令行卷曲到PHP卷曲和PHP卷曲返回空白文件

时间:2013-08-22 11:53:01

标签: php curl command-line

我想使用此网站上的API将.html文件转换为.epub文件https://ebookglue.com/docs 他们在命令行卷曲中有示例,但我想使用PHP卷曲,不知道如何将其正确转换为PHP卷曲

这是命令行卷曲

curl -o converted.epub \
-F "token=your-api-key" \
-F "file=@index.html" \
https://ebookglue.com/convert

这是我到目前为止所做的,它不起作用并返回空白dat.epub文件

$token  =    "token";
$tmpfile = $_FILES['file']['tmp_name'];
$filename = basename($_FILES['file']['name']);

$data = array(
    'token'  => $token,
    'file'          =>  '@'.$tmpfile.';filename='.$filename,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ebookglue.com/convert");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
$out = curl_exec($ch);
curl_close($ch);
$fp = fopen('data.epub', 'w');
fwrite($fp, $out);
fclose($fp);

1 个答案:

答案 0 :(得分:2)

您没有设置POST选项:

curl_setopt($ch, CURLOPT_POST, 1);

如果不起作用:

我注意到你是通过SSL连接的。除非您已对所有证书进行排序,否则请尝试此

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

但请阅读这意味着什么。

相关问题