G
G
GeKskill2020-05-07 18:45:18
PHP
GeKskill, 2020-05-07 18:45:18

PHP + cURL file saving?

There is a page that generates and gives the file through the header:

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=file.txt");

On the local machine, another php script checks if the directory contains a file.
If it is not there, then it downloads it to this very folder ...
I can’t google normally, how to send a request to the address and save the given file to the right folder?

There is this, but it doesn't work:
$source = "example.com/file.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
$error = curl_error($ch); 
curl_close ($ch);
var_dump($error);
$destination = "/var/fn/file.txt";
file_put_contents($destination,$data);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GeKskill, 2020-05-07
@GeKskill

It turned out that everything works... PHP needed write permissions to the .
On the advice of ThunderCat , recording can be done using file_put_contents()
Maybe it will come in handy for someone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question