2012-02-22 51 views
0
$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文件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

@ user914425这可能是一些与你的文件权限。尝试'chmod 777 -R/var/www/vhosts/domain.com/httpdocs/temp /'并重试。一旦您发现问题 – 2012-02-22 03:26:17

+0

让我更改为777的文件夹权限,请将权限切换为更安全。 – user914425 2012-02-22 17:14:27

回答

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)); 
?>