0

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>
3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by cereal
0

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

1

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.