21,890
社区成员
发帖
与我相关
我的任务
分享
guuk 武装部
guwv 一部分
guww 残疾人
guxa 开门红
guyk 下意识
guyw 下半夜
gvav 一刀切
a.php
$file = file_get_contents('file.txt');
$content = explode("\n", $file);
$url = 'http://localhost/result.php'; // 这里需用http
$result = array();
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
foreach($content as $row){
$t = postdata($url, $row);
$result[] = array('row'=>$row, 'posttime'=>$t);
// 提示
if($t){
echo 'post data success<br>';
}else{
echo 'post data error';
}
}
print_r($result);
function postdata($url, $data){
$pdata = array(
'text' => $data
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'content-type:application/x-www-form-urlencoded',
'content' => http_build_query($pdata)
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
return $result;
}
result.php
$row = isset($_POST['text'])? $_POST['text'] : '';
if($row){
echo date('Y-m-d H:i:s');
}else{
echo 'error';
}