PHP fopen($ url,w)

时间:2012-02-22 02:43:30

标签: php fopen fwrite centos5 fclose

$url="http://www.source.com/top";
$destination=fopen("/var/www/vhosts/domain.com/httpdocs/temp/" . date('m-d-Y'),"w");
echo "dest=$destination<br>";
echo "url=$url<br>";
$source=fopen($url,"r");
$maxsize=5000000000;
$length=0;
while (($a=fread($source,1024))&&($length<$maxsize))
{
$tmpfile=$tmpfile . $a;
$length=$length+1024;

}        
    fwrite($destination,$tmpfile);
fclose($source);
fclose($destination);

以上PHP源代码工作就像我的共享主机帐户上的一个魅力。但是,它无法在我的专用Linux Centos机器上写入文件。在这个Centos机器中,源$ url能够读取正常但是这一行:

     $destination=fopen("/var/www/vhosts/domain.com/httpdocs/temp/" . date('m-d-Y'),"w");

无法在Linux框中写入文件。我尝试在linux root用户下运行上面的代码(例如php file-name.php)并且能够创建文件但无法读取源文件:

     $destination=fopen("/var/www/vhosts/domain.com/httpdocs/temp/" . date('m-d-Y'),"w");

我收到403错误。我对这台Linux Centos机器的情况非常困惑。就像我之前在这个Centos框中发布的那样,我在同一页面的提交之间遇到了Session variables return empty的问题。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

为什么不简单地做?:

<?php 
error_reporting(E_ALL);/*Debug any permission problems*/
$url="http://www.source.com/top";
$temp="/var/www/vhosts/domain.com/httpdocs/temp/".date('m-d-Y').".tmp";

file_put_contents($temp,file_get_contents($url));
?>