Copy the contents of a Json via PHP and send to the server

Asked

Viewed 585 times

1

It is possible via PHP copy Json content from a page (an API that generates a json dynamic) like this http://www.folhacar.com.br/frontendnovo.php/api/listMarcas and save to a directory within my site "json/file.json"? As I could create a cron task to always do this 1 time per day.

If it is not possible I will always need to access this api, copy the content, create a json and upload to the folder I want?

  • Related: http://answall.com/questions/38725/%C3%89-poss%C3%Advel-fazer-um-post-de-um-file-automatically

  • Fabio sees if the question I posed as duplicate answers your question.

1 answer

1


In this way:

$string  = file_get_contents("/home/pasta/test.json");

$arquivo = fopen('arquivo.json','w+');

if($arquivo){
    if (!fwrite($arquivo, $sring)){
        echo('Não foi possível atualizar o arquivo');
    }
    echo 'Arquivo atualizado com sucesso<br>';
    fclose($arquivo);
}
  • It worked perfectly, thank you Ricardo!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.