PHP如何实现获取网络上的文件?

PHP可以获取网络上的文件吗?PHP如何实现获取网络上的文件?请看实例代码:

<!– 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);
//当我们完成工作后,关闭到源“文件”的连接。
fclose($dynpage);
//打开临时文件(同时在这个过程中建立)以用来写入(注意’w’的用法).
$tempfile = fopen($tempfilename, ‘w’);
//处理错误
if (!$tempfile) {
echo("<P>Unable to open temporary file ".
"($tempfilename) for writing. Static page ".
"update aborted!</P>");
exit();
}
//将静态页面的数据写入到临时文件中
fwrite($tempfile, $htmldata);
//完成写入后,关闭临时文件。
fclose($tempfile);
//如果到了这里,我们应该已经成功地写好了一个临时文件,
//现在我们可以用它来覆盖原来的静态页面了。
$ok = copy($tempfilename, $targetfilename);
//最后删除这个临时文件。
unlink($tempfilename);
?>
<P>Static page successfully updated!</P>
</BODY>
</HTML>
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » PHP如何实现获取网络上的文件?

207 评论

  1. order tadalafil 10mg for sale cialis mg 5 sildenafil mail order usa

  2. brand doxycycline 100mg doxycycline drug furosemide 100mg cheap

  3. purchase isosorbide generic imdur online order telmisartan 20mg pills

  4. order medroxyprogesterone 10mg online cheap biltricide price order periactin 4mg without prescription

  5. professional research paper writers gambling casino online casino bonus

  6. over the counter cialis viagra australia sildenafil 150mg for sale

  7. domperidone 10mg canada domperidone uk oral cyclobenzaprine

  8. online casino games for real money cialis price usa cialis overnight

  9. prednisone 40mg without prescription vermox brand vermox price

  10. oral naprosyn 500mg order cefdinir buy lansoprazole 30mg pills

  11. brand amoxicillin 1000mg amoxil price buy ivermectin for humans

  12. Thank you for great content. Hello Administ. Onwin , Onwin Giriş , Onwin Güncel Giriş , Onwin Yeni Adres , onwin

  13. prednisone 20mg cheap deltasone price generic amoxil 250mg

  14. cheap sildenafil brand lyrica propecia 5mg sale

  15. order simvastatin 20mg for sale sildenafil 20 mg sildenafil next day delivery

  16. atorvastatin 40mg ca viagra medication purchase sildenafil without prescription

  17. cialis for sale online how to get cialis fda approved over the counter ed pills

  18. order neurontin without prescription buy doxycycline 200mg buy doxycycline 200mg generic

  19. order starlix 120 mg for sale capoten order buy atacand 8mg online cheap

  20. order tegretol 400mg generic cost lincomycin order lincomycin 500mg generic

  21. order estrace 1mg online lamictal 50mg cheap buy minipress 2mg without prescription

  22. triamcinolone over the counter aristocort 4mg us oral loratadine 10mg

  23. buy acillin for sale acillin uk buy generic metronidazole 200mg

  24. which of the following bacteria have become resistant to ciprofloxacin and levofloxacin https://ciprofloxacindik.com/ ciprofloxacin dose for travellers diarrhoea

  25. buy molnunat 200 mg generic generic molnunat buy omnicef 300mg generic

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡