In short, no. Javascript is client-side and run long after the php script has executed - they cannot talk to each other. Perhaps you could use JS to reload the page, sending a variable in the URL. IE your javascript would be something like:
if(someCondition) window.location = "yoursite.com/page.php?filenum=" +files[filenum];
Then your php would look for said variable as it executes:
<?php $filenum=$_GET['filenum']; ?>
if(someCondition) window.location = "yoursite.com/page.php?filenum=" +files[filenum];
Then your php would look for said variable as it executes:
<?php $filenum=$_GET['filenum']; ?>