<?php
## 环境php7.3
// <!DOCTYPE html>
// <html>
// <head>
// <meta charset="utf-8">
// <meta name="viewport" content="width=device-width, initial-scale=1">
// <title></title>
// </head>
// <body>
// <form enctype ="multipart/form-data">
// <input type="file" name="filename">
// </form>
// </body>
// </html>
$params['filename'] = $data['filename']; // {/20240229/123456.zip}
$params['material_type'] = $data['material_type']; //资源内容,字节流 {radio} {1:营业执照,2:小程序图标}
$url = "https://open.microapp.bytedance.com/openapi/v1/tp/upload_pic_material";
$url .= '?' . http_build_query($params);
//这里带的header头并不一定是我这种,具体的是取决于对方API那边要什么
$headers = array('content-type:multipart/form-data; boundary=---7MA4YWxkTrZu0gW');
//一定要是决对路径
$filename = "www/wwwroot/www.baidu.com/Uploads".$params['filename'];
# php5.5之前 '@'.$file;就可以进地文件上传
# $ret['pic'] = '@'.$file;
# php5.6之后用此方法 new CURLFile 至于要不要带 / 看你的命名空间有的框架需要,有的则不需要
$curlname = new \CURLFile($filename); //这里因为没有用过小于php 7.1的版本所以只用了CURLFile
$postData = [
'material_file' => $curlname,
'material_type' => $params['material_type'],
];
$result = isvServiceCurl($url,$postData,$headers);
echo "<pre>";
print_r($result);
function isvServiceCurl($url,$postData,$headers){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output,true);
}
?>