Every first time I create a .txt on my server using a Form, it writes like a charm, but when I add a new line in the .txt using also the Form, and view the .txt from a simple file browser made by PHPToys the new line in the .txt cannot be viewed, the old line is still there but the new line does not add up, but when i open the .txt on a notepad, the new line is there, what is the code to make the .txt updated or some kind of reload or refresh so that the new added line can be seen on the .txt using a file browser.

here is my file browser code:

<?php
function showContent($path){
$path = "records/";
   if ($handle = opendir($path))
   {
       $up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
       

       while (false !== ($file = readdir($handle)))
       {
           if ($file != "." && $file != "..")
           {
               $fName = $file;
               $file = $path.'/'.$file;
               if(is_file($file)) {
                   echo "<tr><td><img src='style/file2.gif' width='16' height='16' alt='file'/> <a href='".$file."'>".$fName."</a></td>"
                            ."<td align='right'>".date ('d-m-Y H:i:s', filemtime($file))."</td>"
                            ."<td align='right'>".filesize($file)." bytes</td></tr>";
               } elseif (is_dir($file)) {
                   print "<tr><td colspan='2'><img src='style/dir2.gif' width='16' height='16' alt='dir'/> <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
               }
           }
       }

       closedir($handle);
   }	

}

if (isset($_POST['submitBtn'])){
	$actpath = isset($_POST['path']) ? $_POST['path'] : '';	
} else {
	$actpath = isset($_GET['path']) ? $_GET['path'] : '';	
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="main">
     

      <div class="caption">Records: <?php echo $actpath ?></div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
<?php
			showContent($actpath);        
?>
        </table>
     </div>
    </div>
</body>

This may just be the caching of your browser.

yes but any codes to use? how to prevent browser from caching the .txt file.... Thanks for the reply.

Turn off caching, start reading here. Although it may not always work.

Together with pritaeas suggest, you can also append a random string to the end of the file:

<a href="/path/file.txt?random_string">file name</a>

you won't need that value to open the file and the browser will read always a new link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.