php 文件流提交 没有使用圈a形式
//图片url地址
$pic_url = "http://img.adbox.sina.com.cn/pic/1505759360-1398150715642.jpg";
$api_url = "http://upload.admin.mp.sina.com.cn/mpimg/index.php?show_type=json";
$delimiter = "-------------" . uniqid();
$delimiter = md5(time());
$fileFields = array(
"mpImageFile" => array(
"type" => "image/jpg",
"content" => file_get_contents($pic_url),
)
);
$postFields = array(
"uid" => "1764439395",
"srctype" => "1"
);
$data = "";
foreach ($postFields as $name => $content) {
$data .= "--" . $delimiter . " ";
$data .= "Content-Disposition: form-data; name="" . $name . "";". " "; ;
$data .= " ";
$data .= $content . " ";
}
foreach ($fileFields as $name => $file) {
$data .= "--" . $delimiter . " ";
$data .= "Content-Disposition: form-data; name="" . $name . "";" ." filename="" . $name . """ . " ";
$data .= "Content-Type: " . $file["type"] . " ";
$data .= " ";
$data .= $file["content"] . " ";
}
$data .= "--" . $delimiter . "-- ";
$handle = curl_init($api_url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_HTTPHEADER , array(
"Content-Type: multipart/form-data; boundary=" . $delimiter,
"Content-Length: " . strlen($data)));
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_exec($handle);
- 上一篇:带你学习世界上最好的语言PHP(七)
- 下一篇:php生成html文件实例代码