We need to update the software on the server in real-time, so we need to request and download the file, then save it to the server. We can use cURL to complete the download task.

Code

The overall idea is to first request the file using cURL, store the data in a variable, and then write it to a file.

We need to initialize a curl, then request this address, and use file operations fopen and fwrite to complete the file saving.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$url = "https://www.g2022cyk.top/sitemap.xml";
$filename = "sitemap.xml"
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
$myfile = fopen($filename, "w") or exit();
fwrite($myfile, $output);
fclose($myfile);
curl_close($ch);