Php 为什么可以';不下载网页到我的目标?

Php 为什么可以';不下载网页到我的目标?,php,Php,代码在我的本地pc中保存为“/tmp/down.php” <?php function downfile($fileurl) { ob_start(); $filename=$fileurl; header( "Content-type: application/octet-stream "); header( "Accept-Ranges: bytes "); header( "Content-Disposition:

代码在我的本地pc中保存为“/tmp/down.php”

<?php 
function downfile($fileurl)
    {
     ob_start(); 
     $filename=$fileurl;
     header( "Content-type:  application/octet-stream "); 
     header( "Accept-Ranges:  bytes "); 
     header( "Content-Disposition:  attachment;  filename= '/tmp/test'"); 
     $size=readfile($filename); 
     header( "Accept-Length: " .$size);
     }

$url="http://www.yahoo.com";
downfile($url);
?> 

,因为您没有将其保存到
/tmp/test
。尝试以下方法:

file_put_contents("/tmp/test", fopen("http://www.yahoo.com", 'r'));

/tmp/a是一个公共网站吗?不,它是我本地电脑中的一个私有目录。我想知道为什么我的代码不能将网页下载到目标文件中,而是在终端中显示。@这是一篇文章,因为你告诉它在浏览器中显示。如果要将其另存为目标文件,则必须告诉它使用
file\u put\u content()
或类似函数将其另存为目标文件。