【发布时间】:2014-07-01 13:07:49
【问题描述】:
我正在尝试调用 ConvertAPI.com/Word2Pdf,但没有成功。
我的示例代码是:
$fileToConvert = 'test.docx';
$apiKey = *******;
$postdata = array('OutputFileName' => 'test.pdf', 'ApiKey' => $apiKey, 'File' => $fileToConvert);
$ch = curl_init("http://do.convertapi.com/Word2Pdf");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
var_dump($result);
我得到的结果类似于:“HTTP/1.1 100 Continue HTTP/1.1 400 'File' 参数不能为空。请设置值。缓存控制:无缓存,无存储杂注:无-cache Content-Type: text/html..."
我在这里做错了什么?
【问题讨论】:
-
test.docx 文件是否存在?也许尝试使用该文件的绝对路径?
-
是的。它存在,并且与此 php 文件位于同一文件夹中...
-
我尝试过使用绝对路径,但得到了相同的结果...
-
自从我的主机从 php 5.4 升级到 php 5.6 我得到了同样的错误。你找到任何解决方案了吗? (不是最统一的方式)。我已经向他们的支持部门发送了多封电子邮件,但根本没有任何回应......
-
@COBIZwebdevelopment 正如我在已接受答案的评论中所写,我没有使用 unirest,解决方案是将 @ 添加到文件名: $postdata = array('OutputFileName' = > 'test.pdf', 'ApiKey' => $apiKey, 'File' => "@" . $fileToConvert);
标签: php convertapi