这的页面:          <body>
<form action="" method="post">
<input name="file" type="file" />
<input name="sub" type="submit" value="导出" />
</form>
<?php 
  if($_POST[sub]==!null)
  {
$file=$_POST[file];
$conn = mysql_connect("localhost","root","123456") 
or die("Could not connect: " . mysql_error());
mysql_select_db("test",$conn);
mysql_query("SET NAMES gb2312") or die(mysql_error());
$result = mysql_query("SELECT name  FROM `skyinfo`");
$txt;
 while ($row = mysql_fetch_array($result)) 
{
   $txt.=$row[0]."\r\n";
}
mysql_free_result($result);
file_put_contents($file,$txt);
mysql_close($conn);
if($file)
{
echo "导出成功";
}
else
{
echo "导出失败";
}
  }
?>
</body>
     导出来之后会把之前的里面.txt里面的内容覆盖掉,,这么才能不被覆盖掉,,哪位大哥能解决下

解决方案 »

  1.   

    又是你啊
    这种的问题,自己看看书就会了。
    总是问人可不行
    php手册,查一下
    fopen
    fwrite
    fclose
      

  2.   

    function file_write_data($filename,$data,$mode='ab')
    {
    $handle=fopen($filename,$mode);
    if($handle===false)
    {
    return false;
    }
    if(flock($handle,LOCK_EX))
    {
    fwrite($handle,$data);
    flock($handle,LOCK_UN);
    }
    fclose($handle);
    return true;
    }调用:
    file_write_data($file,$txt);