0
I need help updating content within a div that is displayed as a result in PHP.
This div contains PHP variables to display the results that are taken from a text file that is in another directory. You can give an auto refresh in a few seconds (even if it is in script or Ajax, but it needs to receive a PHP parameter so that the auto refresh stops when the php function is finished running) ?
This is the content it contains in Div:
<div class="results">
<?php
//abrimos o arquivo em leitura
$arquivo = 'log/speedtest.txt';
$fp = fopen($arquivo, 'r');
//lemos o arquivo
$texto = fread($fp, filesize($arquivo));
//transformamos as quebras de linha em etiquetas <br>
$texto = nl2br($texto);
echo $texto;
?>
</div>
And this is the function that is performed by sending the form:
<?php
if(isset( $_POST['submit'] )) {
if( $_POST['ntestes'] == "0" ) {
echo "<script type='text/javascript'>alert('Último teste realizado.')</script>";
}
if($_POST['ntestes'] >= "1" ) {
echo "<script type='text/javascript'>alert('Testes realizados com sucesso!')</script>";
}
$ntestes = escapeshellarg($_POST["ntestes"]);
$teste = shell_exec('/bin/speedtest ' .$ntestes. ' -l printf $?');
}
?>
This is the form that receives the values for executing the php function above:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="form">
<p>
<label>Número de testes: </label>
</p>
<select name="ntestes">
<option value="0">0</option>
<option value="1"selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<input type="submit" name="submit" class="execute" value="Executar">
<a href="log/" class="btn" target="_blank">Visualizar Logs</a>
</form>
Any idea how I can do that ?
To
div
is on the pagelog/
?– Andrei Coelho
@Andreicoelho No, this log/ is another page to display logs only.
– Rooh Macedo
Is everything on the same page? All these codes?
– Andrei Coelho
@Andreicoelho Yes, all the code posted on the question is from the same page.
– Rooh Macedo
And you want the div "Results" to keep updating, using that php code that’s inside it, that’s it?
– Andrei Coelho
This, but it has to stop when the php function is finished running.
– Rooh Macedo
Stop her when the
ntestes
is equal to0
. Is that it? You have to stop when you finish running Speedtest– Andrei Coelho
In the case when the variable
$teste
is equal to0
so I put the remoteshell_exec
within a variable. This variable will receive the value as a parameter of the executed function.– Rooh Macedo
Let’s go continue this discussion in chat.
– Andrei Coelho