我正在尝试使用 PHP/CURL 调用 ConvertAPI RESTful API 将表单上传 PDF 转换为 PNG。文件上传正在工作,因为文件显示在服务器上,但是 curl_getinfo 没有返回任何内容,显示 [size_upload] => 0 和 [size_download] => 0。有人可以指出我的代码中的错误吗?
define("UPLOAD_DIR", "./tmp/");
$rest_url="https://do.convertapi.com/Pdf2Image";
$up_file=UPLOAD_DIR.rand(100,999)."_".basename($_FILES['fileField']['name']);
if (!move_uploaded_file($_FILES['fileField']['tmp_name'], $up_file)) {
die("Possible file upload attack!");
}
$cfile=new CURLFile($up_file);
$params=array(
"ApiKey" => 11111111,
"OutputFormat" => "png",
"OutputFileName" => "converted.png",
"File" => $cfile
);
$ch=curl_init($rest_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$res=curl_exec($ch);
$headers=curl_getinfo($ch);
curl_close($ch);
echo "<pre>";
print_r($headers);
var_dump($res);