如何将curl转换为php我尝试不起作用

时间:2014-06-23 11:07:07

标签: php curl

这张图片来自萤火虫。它发布图像二进制数据1

curl 'http://xxxxx.com/xxxx/cccc' 
-H 'Content-Type: multipart/form-data;            
boundary=---------------------------1145250413327763230421052055' --data-binary 
$'-----------------------------1145250413327763230421052055\r\nContent-Disposition: form-data; 
name="user_image"; filename="dscn6949_938.jpg"\r\nContent-Type: image/jpeg\r
\n\r\n-----------------------------1145250413327763230421052055--\r\n'

我将此代码尝试到下面但不能正常工作

$ch = curl_init();
$headers = array(
"Content-Type: multipart/form-data;   
boundary=---------------------------1145250413327763230421052055"
);
curl_setopt($ch, CURLOPT_URL,"http://xxxxx.com/xxxx/cccc");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$datapost = array(
            "user_image" => "@111.jpg".";filename=111.jpg;type=image/jpeg"
            );

curl_setopt ($ch, CURLOPT_POSTFIELDS, $datapost);
$result = curl_exec($ch);

0 个答案:

没有答案