程序员的知识教程库

网站首页 > 教程分享 正文

php 文件流提交 没有使用圈a形式(php文件运行显示无法显示页面)

henian88 2024-09-07 15:16:59 教程分享 139 ℃ 0 评论

//图片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 . "\r\n";

$data .= 'Content-Disposition: form-data; name="' . $name . '";'. "\r\n"; ;

$data .= "\r\n";

$data .= $content . "\r\n";

}

foreach ($fileFields as $name => $file) {

$data .= "--" . $delimiter . "\r\n";

$data .= 'Content-Disposition: form-data; name="' . $name . '";' .' filename="' . $name . '"' . "\r\n";

$data .= 'Content-Type: ' . $file['type'] . "\r\n";

$data .= "\r\n";

$data .= $file['content'] . "\r\n";

}

$data .= "--" . $delimiter . "--\r\n";

$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);

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表