最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP stream_context_create()作用和用法分析

 更新時(shí)間:2011年03月29日 16:32:15   作者:  
創(chuàng)建并返回一個(gè)文本數(shù)據(jù)流并應(yīng)用各種選項(xiàng),可用于fopen(),file_get_contents()等過程的超時(shí)設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程。
作用:創(chuàng)建并返回一個(gè)文本數(shù)據(jù)流并應(yīng)用各種選項(xiàng),可用于fopen(),file_get_contents()等過程的超時(shí)設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程。
函數(shù)原型:resource stream_context_create ([ array $options [, array $params ]] )
用法
例子一:
復(fù)制代碼 代碼如下:

<?php
$opts = array( 'http-->array(
'method'=&gt;"GET",
'header'=&gt;"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
/* Sends an http request to www.fzitv.net
with additional headers shown above */
$fp = fopen('http://www.fzitv.net', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>

例子二:
復(fù)制代碼 代碼如下:

<?php
$opts = array( 'http-->array(
'method'=&gt;"GET",
'header'=&gt;"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
?>
You would setup the header this way:
<?php
$opts = array( 'http-->array(
'method'=&gt;"GET",
'header'=&gt;array("Accept-language: en",
"Cookie: foo=bar",
"Custom-Header: value")
)
);
$context = stream_context_create($opts);
?>

例子三:
復(fù)制代碼 代碼如下:

<?php
$opts = array('http' => array('proxy' => 'tcp://127.0.0.1:8080', 'request_fulluri' => true));
$context = stream_context_create($opts);
$data = file_get_contents('http://www.fzitv.net', false, $context);
echo $data;
?>

例子四:
復(fù)制代碼 代碼如下:

<?php
function do_post_request($url, $postdata, $files = null)
{
$data = "";
$boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10);
//Collect Postdata
foreach($postdata as $key => $val)
{
$data .= "--$boundary\n";
$data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n";
}
$data .= "--$boundary\n";
//Collect Filedata
foreach($files as $key => $file)
{
$fileContents = file_get_contents($file['tmp_name']);
$data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\n";
$data .= "Content-Type: image/jpeg\n";
$data .= "Content-Transfer-Encoding: binary\n\n";
$data .= $fileContents."\n";
$data .= "--$boundary--\n";
}
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary='.$boundary,
'content' => $data
));
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
//set data (in this example from post)
//sample data
$postdata = array(
'name' => $_POST['name'],
'age' => $_POST['age'],
'sex' => $_POST['sex']
);
//sample image
$files['image'] = $_FILES['image'];
do_post_request("http://www.fzitv.net", $postdata, $files);
?>

相關(guān)文章

最新評論

平度市| 桐梓县| 隆尧县| 施秉县| 德安县| 新平| 岚皋县| 高唐县| 安顺市| 双柏县| 湘潭市| 逊克县| 津市市| 香河县| 凤冈县| 剑川县| 蕉岭县| 湖南省| 康定县| 南京市| 临澧县| 柞水县| 伊川县| 怀安县| 汉川市| 乐都县| 景泰县| 横峰县| 瓮安县| 平安县| 郧西县| 周宁县| 静乐县| 台东市| 商城县| 金堂县| 墨脱县| 奈曼旗| 商水县| 柯坪县| 霍邱县|