php file_get_contents 使用3法
<?php //GET function http_get($url, $params){ return file_get_contents($url.‘?‘.http_build_query($params)); } //POST function 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); } //UPLOAD function 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); } ?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。