<!– generateindex.php –>
<?php
//设置我们将要使用的文件
$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
//首先删除上次操作可能遗留下来的临时文件。
//这个过程可能会提示错误,所以我们使用@以防止报错。
@unlink($tempfilename);
//通过一个url的请求装入动态版本。
//在我们接收到相关内容之前,web服务器会对php进行处理
//(因为本质上我们是在模拟一个web浏览器),
//所以我们将获得的是一个静态的html页面。
//’r’指出我们只要求对这个“文件”进行读操作。
$dynpage = fopen($srcurl, ‘r’);
//处理错误
if (!$dynpage) {
echo(“<p>unable to load $srcurl. static page “.
“update aborted!</p>”);
exit();
}
//将这个url的内容读入到一个php变量中。
//指定我们将读取1mb的数据(超过这个数据量一般是意味着出错了)。
$htmldata = fread($dynpage, 1024*1024);
//当我们完成工作后,关闭到源“文件”的连接。
fclo($dynpage)北大研修班;
//打开临时文件(同时在这个过程中建立)以用来写入(注意’w’的用法).
$t接收证明怎么开empfile = fopen($tempfilename, ‘wR摄影专业17;);
//处理错误
if (!$tempfile) {
echo(“<p>unable to open temporary file “.
“($tempfilename) for writing. static page “.
“update abor会计实践报告ted!</p>”);
exit();
}
//将静态页面的数据写入到临时文件全国文明城市名单中
fwrite($tempfile, $htmldata);
//完成写入后,关闭临时文件。
fclo($tempfile);
//如果到了这里,我们应该已经成功地写好了一个临时文件,
//现在我们可以用它来覆盖原来的静态页面了。
$ok = copy($tempfilename, $targetfilename);
//最后删除这个临时文件。
unlink($tempfilename);
?>
<p>static page successfully updated!</p>
</body>
</html>
本文发布于:2023-04-06 08:42:29,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/f10ee71f3d8847ee1f4521c2c18bc362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:如何使用PHP获取网络上文件.doc
本文 PDF 下载地址:如何使用PHP获取网络上文件.pdf
留言与评论(共有 0 条评论) |