I'm trying to call a JavaScript function on a button in html. Both the button and the JavaScript function are in the same file, however I am having an error saying that the function is not available.
function countFiles() {
  $directory = "/uploadFiles";
  $filecount = 0;
  $files = glob($directory.
    "*");
  if ($files) {
    $filecount = count($files);
  }
  if ($filecount > 0) {
    echo '<script type="text/javascript">',
      'window.location.href = "decrypt.php";',
      '</script>';
  } else {
    echo "<script type='text/javascript'>alert('Precisa de inserir pelo menos 1 ficheiro');</script>";
  }
}<button onclick="countFiles()">Desencriptar</button> 
     
     
    