// cocos 显示一个图片到 quad 上面
let material = cc.Material.createWithBuiltin('unlit');
material.define('USE_DIFFUSE_TEXTURE', true);
material.setProperty('diffuseTexture', texture2d);
this.monster.getComponent(cc.MeshRenderer).setMaterial(0, material);
// php 发送 multipart/form-data 内容
static function postMultiData($url, $postdata, $files = null)
{
$data = "";
$boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10);
//Collect Postdata
foreach($postdata as $key => $val)
{
$data .= "--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"".$key."\"\r\n\r\n".$val."\r\n";
}
$file = $files[0];
$handle = fopen($file, "rb");//读取二进制文件时,需要将第二个参数设置成'rb'
//通过filesize获得文件大小,将整个文件一下子读到一个字符串中
$fileContents = fread($handle, filesize ($file));
fclose($handle);
p($file);
p(filesize($file));
$data .= "--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"file\"\r\n\r\n".$fileContents."\r\n";
$data .= "--$boundary\r\n";
$arrContextOptions=array(
"ssl"=>array(
"cafile" => self::$pem,
"verify_peer"=> true,
"verify_peer_name"=> true,
),
'http' => [
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary='.$boundary,
'content' => $data
]
);
$r = file_get_contents($url, false, stream_context_create($arrContextOptions));
return $r;
}