There are two ways to do this with PHP.
Example with file_get_contents
:
This function will access the page and download all its content, to save, we can use fopen
or file_put_contents
.
<?php
while (true) {
/* Captura a data atual */
$date = date('Y_m_d');
/* Captura o tempo patual */
$time = date('H_i_s');
/* Monta a URL com a data e o tempo */
$url = "http://appsite/caminho/caminho2/Content/caminho3/Painelimg/{$date}/{$time}.PNG";
/* Faz uma requisição para a URL e salva o conteúdo em binário na variável */
$content = file_get_contents($url, FILE_BINARY);
/* Cria o arquivo no servidor com o conteúdo baixado */
file_put_contents( "{$time}.png", $content, FILE_BINARY );
/* Aguarda 10 segundos */
sleep(10);
}
Ready! It’s working. The problem is while(true)
will be infinite and therefore you may have a problem with the server resources.
If it’s something sporadic, no problem.
Example with curl
:
This function will also make a request and return the data, but will have a few more lines. The advantage is that it is more robust than the previous function.
To save, we can use fopen
or file_put_contents
.
<?php
while (true) {
/* Captura a data atual */
$date = date('Y_m_d');
/* Captura o tempo patual */
$time = date('H_i_s');
/* Monta a URL com a data e o tempo */
$url = "http://appsite/caminho/caminho2/Content/caminho3/Painelimg/{$date}/{$time}.PNG";
/* Cria o arquivo. Caso ele já exista, sobrepõe */
$file = fopen("{$time}.png", "w+");
/* Instancia o objeto */
$ch = curl_init($url);
/* Define as configurações */
curl_setopt_array($ch, [
/* Informa que deseja capturar o valor retornado */
CURLOPT_RETURNTRANSFER => true,
/* Indica o "Resource" do arquivo onde será salvado */
CURLOPT_FILE => $file
]);
/* Fecha a conexão da requisição e do arquivo */
curl_close($ch);
fclose($file);
/* Aguarda 10 segundos */
sleep(10);
}
I realized that the image by the way I indicated it is all black but on the site it is black but with a few letters, I think it is done in canvas, when I saved by the mouse everything comes right however by the code or the link I posted straight from the image comes all black, will q there is another way?
– lxxtomxxl
@Ixxtomxxl if possible put the image link, it is easier to test. It is necessary to check the extension as well. Have you tested with both forms or just one of them?
– Valdeir Psr
so the link only works within the company, I tried to get only the div that contains the image with file_gets_contents worked on other sites, but not on that. If you have another way I would like to present you with something, if possible within the rules of the site.
– lxxtomxxl