21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
if (isset($_POST['file'])) {
$file = fopen($path, "r") or exit("无法打开文件!");
// 读取文件每一行,直到文件结尾
$i=1;
while(!feof($file))
{
if($i%2!=0){
echo fgets($file). $i."<br>";
}else{
echo fgets($file). "<br>";
}
$i++;
}
fclose($file);
}
echo $_POST['file'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
<form id="myForm" name="myForm" method="POST" action="txt.php" />
<input type="file" name="file" id="file">
<input value="确定" type="submit" />
</form>
</body>
</html>
<?php
if (isset($_POST['file'])) {
$path=$_POST['file'];
$file = fopen($path, "r") or exit("无法打开文件!");
// 读取文件每一行,直到文件结尾
$i=1;
while(!feof($file))
{
if($i%2!=0){
echo fgets($file). $i."<br>";
}else{
echo fgets($file). "<br>";
}
$i++;
}
fclose($file);
}
echo $_POST['file'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
<form id="myForm" name="myForm" method="POST" action="txt.php" />
<input type="file" name="file" id="file">
<input value="确定" type="submit" />
</form>
</body>
</html>
只能打开最早打开过的那个txt文件,别的一律打不开,而且显示的还是没修改前的txt内容。