Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用ConvertAPI Word2Pdf?_Php_Convertapi - Fatal编程技术网

Php 如何使用ConvertAPI Word2Pdf?

Php 如何使用ConvertAPI Word2Pdf?,php,convertapi,Php,Convertapi,我试图调用ConvertAPI.com/Word2Pdf,但没有成功 我的示例代码是: $fileToConvert = 'test.docx'; $apiKey = *******; $postdata = array('OutputFileName' => 'test.pdf', 'ApiKey' => $apiKey, 'File' => $fileToConvert); $ch = curl_init("http://do.convertapi.com/Word2Pdf

我试图调用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.1100 Continue HTTP/1.1400“File”参数不能为null。请设置值。缓存控制:无缓存,无存储Pragma:无缓存内容类型:text/html

我做错了什么?

使用库试试这个


test.docx文件是否存在?也许可以尝试使用该文件的绝对路径?是的。它存在,并且它位于与此php文件相同的文件夹中…我尝试使用绝对路径,但得到了相同的结果…自从我的主机从PHP5.4升级到PHP5.6后,我得到了相同的错误。你找到解决办法了吗?不是最简单的方式。我已经向他们的支持部门发送了多封电子邮件,根本没有任何回应。@COBIZwebdevelopment正如我在对接受的答案的评论中所写的那样,我没有使用unirest,解决方案是在文件名中添加@:$postdata=array'OutputFileName'=>'test.pdf','ApiKey'=>$ApiKey',file'=>@$文件转换;几分钟前我用同样的方法解决了这个问题。密钥是文件名的@prefix。我正在尝试这个解决方案,但没有效果,有什么建议吗?
$response = Unirest::post(
  "http://do.convertapi.com/Word2Pdf?ApiKey=<Your api key>",
  array(
    "File" => "@/tmp/file.path",
    "OutputFormat" => "pdf",
  )
);