<span>can PHP get the files on the network? How does PHP implement getting files on the network? Take a look at the example code:
<!--generateindex.php-->
<?php
//Set the file we are going to use
$srcurl = "http://localhost/index.php";
$tempfilename = "tempindex.html";
$targetfilename = "index.html";
?>
<HTML>
<HEAD>
<TITLE>
generating <?php Echo ("$targetfilename");?>
</TITLE>
</HEAD>
<BODY>
<p>generating <?php Echo ("$targetfilename");?>...</p>
<?php
//First delete the temporary files that might be left over from the last operation.
//This process may prompt an error, so we use @ To prevent errors.
@unlink ($tempfilename);
//The dynamic version is loaded via a URL request.
//Before we receive the relevant content, the Web server will process PHP
//(because essentially we are impersonating 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 error
if (! $dynpage) {
Echo ("<p>unable to load $srcurl. Static page.
"Update aborted!</p>");
exit ();
}
//Read the contents of this URL into a PHP variable.
//Specifies that we will read 1MB of data (more than this amount of data generally means that there is a mistake).
$htmldata = fread ($dynpage, 1024*1024);
//When we have finished working, turn off the connection to the source "file".
fclose ($dynpage);
//Open temporary file (established in the process) to write (note ' W ' usage).
$tempfile = fopen ($tempfilename, ' W ');
//Handling error
if (! $tempfile) {
Echo ("<p>unable to open temporary file".
"($tempfilename) for writing. Static page.
"Update aborted!</p>");
exit ();
}
//writes static page data to the temporary file
fwrite ($tempfile, $htmldata);
after
//finish writing, close the temporary file.
fclose ($tempfile);
//If we get here, we should have succeeded in writing 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);
?>
<p>static page successfully updated!</p>
</BODY>
</HTML>