You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PHP CURL调用ConvertAPI转PDF为PDF/A时遇500错误求助

问题解决:ConvertAPI PDF转PDF/A返回5009错误(File id is not valid.)

问题根源

你用@符号指定文件路径的上传方式,在PHP 5.5及以上版本已被废弃,ConvertAPI无法正确解析上传的文件,因此触发"File id is not valid."错误。

修复代码

替换原文件上传参数的构造方式,改用CURLFile类处理文件上传:

// 先验证文件路径有效性(可选但推荐)
$filePath = trim($hdd_path . $_file_name);
if (!file_exists($filePath)) die("文件不存在:$filePath");
if (!is_readable($filePath)) die("文件无读取权限:$filePath");

// 用CURLFile构造上传文件对象
$uploadFile = new CURLFile($filePath);

$formData = [
    'File' => $uploadFile,
    'StoreFile' => true,
];

$apiUrl = 'https://v2.convertapi.com/convert/pdf/to/pdfa?Secret=' . getConfig('external_services:convertapi_com:secret');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formData);
// 移除强制指定SSL版本的配置,让curl自动适配兼容版本
// curl_setopt($ch, CURLOPT_SSLVERSION, 6);

$result = curl_exec($ch);

// 新增CURL错误排查
if (curl_errno($ch)) {
    echo 'CURL错误信息:' . curl_error($ch);
}
curl_close($ch);

var_dump($result);

额外注意事项

  • 确保$hdd_path . $_file_name拼接后的路径绝对正确,文件真实存在且有可读权限
  • 不要强制指定CURLOPT_SSLVERSION,让CURL自动选择服务器兼容的SSL/TLS版本,避免版本不兼容引发的隐性问题

内容的提问来源于stack exchange,提问作者Vidmantas Norkus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 22:05:25