I'm currently trying to make a webpage look a bit more modern, but I'm having a bit of trouble adding some relatively simple functionality to a modal window.
On my webpage, a user first uploads a file, then on hitting submit the file gets processed by a shell script (which can take from seconds to minutes depending on the file size).
What I had been doing to show the process status was execute the following bit of code using php:
$cmd = "script.bash -i $input_file";
$PID = shell_exec($cmd . " >> $log 2>&1  & echo $!");
while(is_process_running($PID)){
   echo(" . ");
   ob_flush(); flush();
   sleep(3);
}
In addition to some other information that gets displayed (not shown), this would simply print out a "." every few seconds to give the user an indication that the process was running. On completion, a download link would appear so that the processed data could be retrieved.
What I would like to do now is load this information in a modal window. I have no trouble creating the modal window (using boostrap and javascript) and adding download functionality to it, but I can only do this once the $cmd executed via php is complete. What I would like to do is execute the $cmd, load the modal window, then query the process status and display some sort of indicator in the modal window, and finally create the download link when the process is complete. I believe this needs to be done via AJAX, but I'm a bit confused on how to do this. Here is my code in a bit more detail:
<?
    if($theaction == "run_script" and !$error_msg){
        $cmd = "script.bash -i $input_file";
        $PID = shell_exec($cmd . " >> $log 2>&1  & echo $!");
        while(is_process_running($PID)){ #ensure the process is compete before loading the html
            echo("");
            ob_flush(); flush();
            sleep(3);
        }
        echo "
            <script type=\"text/javascript\">
                $(function() { $(\"#myModalProcess\").modal('show') })
            </script>
            <div class=\"modal fade\" id=\"myModalProcess\" tabinex=\"-1\" role=\"dialog\" aria-hidden=\"true\">
                <div class=\"modal-dialog\">
                    <div class=\"modal-content\">
                        <div class=\"modal-header\">
                            <h4><b>Process ID: $PID</b></h4>
                            <hr>
                            <p>Other stuff here</p>
                            <a type=\"button\" class=\"btn btn-primary\" href='".$_SERVER['PHP_SELF']."?theaction=download&workDir=$workDir&out_folder=$out_folder'>Download Results</a>
                        </div>
                    </div>
                </div>
            </div>
        ";
    }
?>
 
     
    