我有一个接收发布数据表单的网络服务器,其中一部分可以是附加图像。我想使用 curl 将该信息发送到第二台服务器。对于不包含图像的请求,一切正常,但是当原始帖子中包含图像时,我得到:
curl error 26: failed creating formpost data
我知道这表明 curl 无法找到该文件,但我无法确定确切的原因。这是代码
if ($_POST) {
$postData = array();
//copy in the post fields that were posted here
foreach ($_POST as $key => $value) {
$postData[$key] = $value;
}
//copy in the files that have been included
foreach ($_FILES as $key => $value) {
if ($value["tmp_name"]) { //if null, no file was uploaded
$fn = "existing_image.jpg";//(use existing for debugging only
//in reality, would use the tmp image)
$postData[$key] = "@" . realpath($fn) . ";type=" . $value["type"];
$testMsg .= "added file $key value of '" . $postData[$key] .
"'(" . file_exists($fn) . ")\n";
}
}
$testMsg .= "POSTDATA:\n" . print_r($postData, true);
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $postData;
}
这是输出:
added file photo value of '@/var/www/wordpress/somedirectory/php/existing_image.jpg;type=image/jpeg'(1)
POSTDATA:
Array
(
[key1] => 4
[key2] => blah blah some text
[key3] => etc
[keyimage] => @/var/www/wordpress/somedirectory/php/existing_image.jpg;type=image/jpeg
)
该文件确实存在 - 为什么 curl 给我错误?感谢您提供的任何帮助...
编辑:当服务器 1 和 2 是同一台服务器时,我没有同样的问题(即,当我在第二台服务器上设置一个网页来接收发布的数据,然后执行相同的 curl 代码以将信息发送给自己时)。这可能意味着什么,但我显然忽略了一些东西......