0

What I have done so far is a PHP code which is running when the page is refreshed:

<?php
    $pageRefreshed = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';

    if($pageRefreshed) {
        $file01 = file_get_contents("file01.txt");
        $path = "file02.txt";
        $file02= file_get_contents($path);
        if ($file01!== $file02){
            file_put_contents($path, $file01);
        }
    }   
?>

but, I have an HTML button:

<button class="btn" id="refreshPanel" onclick="refresh_panel()">Refresh Panel</button>

and I want to copy the content of file01 into file02 if this button is clicked using pure javascript.

Both files and .html and .js files stored in the same folder in my computer.

Thanks for your help and time in advance!

maziarser
  • 125
  • 1
  • 7

1 Answers1

1

If you are trying to write a file on client machine, You can't do this in any cross-browser way.

If you want to do something like this, you must pass the execution of these actions to server-side

Marco Salerno
  • 5,131
  • 2
  • 12
  • 32