php - 如何在php中使用curl发送文件
问题描述
我曾尝试使用 curl 发送文件以进行 pdf 转换,但我从 API 端收到错误消息。
$file_name_with_full_path = WWW_ROOT . "img/IPG_07_12_2020.xlsx";
if (function_exists('curl_file_create')) {
$cFile = curl_file_create($file_name_with_full_path);
} else {
$cFile = '@' . realpath($file_name_with_full_path);
}
$post = array('file_contents'=> curl_file_create($file_name_with_full_path));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost:3000/convert/office",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 86400,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_POSTFIELDS =>$post,
CURLOPT_HTTPHEADER => array('Content-Type: multipart/form-data'),
));
$result = curl_exec($curl);
并且错误是 {"message":"context has timed out"}.,请分享您的知识,以正确的方式将文件发送到 curl。提前致谢。
解决方案
推荐阅读
- mysql - url的前缀索引的最佳大小是多少(MySQL)
- regex - 如何在sed中匹配序列../../../?
- amazon-web-services - 私有实例中的 AWS 运行状况检查
- java - java - 如何忽略来自java的可空性注释?
- python - 查找行上具有不同数量的两个 Pandas 数据帧之间的欧几里德距离
- javascript - 网站上的购物车 保存有关产品的信息
- javascript - 语言切换器。HTML、CSS、JavaScript
- java - java.sql.SQLIntegrityConstraintViolationException:列“Ciudad”不能为空
- akeneo - 更改 Akeneo CE 3.2 产品默认图像
- java - 在 NavigableMap 中使用 NavigableMap