首页 > 代码库 > php file_get_contents 使用3法
php file_get_contents 使用3法
<?php//GETfunction http_get($url, $params){ return file_get_contents($url.‘?‘.http_build_query($params));}//POSTfunction http_post($url, $params){ $eol = "\r\n"; $content = http_build_query ($params); $header = ‘Content-type: application/x-www-form-urlencoded‘.$eol. "Content-Length: " . strlen($content).$eol; $opts = array(‘http‘ => array( ‘method‘ => ‘POST‘, ‘header‘ => $header, ‘content‘ => $content ) ); $context = stream_context_create($opts); return file_get_contents($url, false, $context);}//UPLOADfunction http_upload($url, $file){ $MULTIPART_BOUNDARY = ‘--------------------------‘.microtime(true); $FORM_FIELD = ‘uploaded_file‘; $header = ‘Content-Type: multipart/form-data; boundary=‘.$MULTIPART_BOUNDARY; $content = "--".$MULTIPART_BOUNDARY."\r\n". "Content-Disposition: form-data; name=\"".$FORM_FIELD."\"; file=\"".basename($file)."\"\r\n". "Content-Type: application/zip\r\n\r\n". file_get_contents($file)."\r\n". "--".$MULTIPART_BOUNDARY."--\r\n"; $context = stream_context_create(array( ‘http‘ => array( ‘method‘ => ‘POST‘, ‘header‘ => $header, ‘content‘ => $content, ) )); return file_get_contents($url, false, $context);}?>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。