Copy the code The code is as follows:
//Set the file we will use
$srcurl = "http://localhost/index.php";
$tempfilename = "tempindex.html ";
$targetfilename = "index.html";
?>
Generating
< ;/TITLE>
Generating ...
//First delete the temporary files that may be left over from the last operation.
//This process may prompt errors, so we use @ to prevent errors.
@unlink($tempfilename);
//Load the dynamic version through a URL request.
//Before we receive the relevant content, the web server will process PHP
//(Because essentially we are simulating a web browser),
//So what we will get is a static HTML page.
//'r' indicates that we only require read operations on this "file".
$dynpage = fopen($srcurl, 'r');
//Handling errors
if (!$dynpage) {
echo("
Unable to load $srcurl. Static page ".
"update aborted!
");
exit();
}
//Read the content of this URL into a PHP variable.
//Specify that we will read 1MB of data (exceeding this amount of data generally means an error has occurred).
$htmldata = fread($dynpage, 1024*1024);
//When we finish our work, close the connection to the source "file".
fclose($dynpage);
//Open the temporary file (also created during this process) for writing (note the usage of 'w').
$tempfile = fopen($tempfilename, 'w');
//Handle errors
if (!$tempfile) {
echo("
Unable to open temporary file ".
"($tempfilename) for writing. Static page ".
"update aborted!
");
exit();
}
//Write the data of the static page into the temporary file
fwrite($tempfile, $htmldata);
//After completing the writing, close the temporary file.
fclose($tempfile);
//If we get here, we should have successfully written a temporary file,
//Now we can use it to overwrite the original static page.
$ok = copy($tempfilename, $targetfilename);
//Finally delete this temporary file.
unlink($tempfilename);
?>
Static page successfully updated!
The above introduces the implementation code of Xi'an Aviation Technology College code and using PHP to obtain network files, including the content of Xi'an Aviation Technology College code. I hope it will be helpful to friends who are interested in PHP tutorials.