【问题标题】:Cannot send image through cURL无法通过 cURL 发送图像
【发布时间】:2012-05-26 06:25:37
【问题描述】:

由于某种原因,我无法通过 cURL 将图像发送到外部服务器。可能是一些小问题,但我已经看了好几个小时的代码,仍然不知道出了什么问题......

$ch = curl_init();

$data = array(
    'fbid' => $userProfile['id'],
    'name' => $userProfile['name'],
    'email' => $userProfile['email'],
    'gender' => $userProfile['gender'],
    'title' => $_POST['title'],
    'original' => '@' . UPLOAD_PATH . $imageFilename,
    'thumbnail' => '@' . UPLOAD_PATH . $thumbnailFilename,
    'cropped' => '@' . UPLOAD_PATH . $croppedImageFilename
);

curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com/curl.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_exec($ch);

文本正在通过,如果我在远程服务器上打印出 $_POST 这就是我得到的...

Array (
    [fbid] => 12345
    [name] => My Name
    [email] => email@domain.com
    [gender] => male
    [title] => Image title
)

任何帮助将不胜感激:P

【问题讨论】:

  • 你使用的是multipart/form-data还是标准的application/x-www-form-urlencoded

标签: php curl remote-server


【解决方案1】:

忘记我的最后一个答案。太仓促了。我相信问题在于您正在 $_POST 中查找文件上传。文件上传包含在 $_FILES 中。

尝试将 $_FILES 的内容转储到远程服务器上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 2020-09-29
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 2020-05-21
    • 1970-01-01
    相关资源
    最近更新 更多