2
$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);

Above PHP source work like a charm on my shared hosting account. However, it fails to write files on my dedicated Linux Centos machine. In this Centos machine the source $url is able read ok but this line:

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

Fails to write the file in Linux box. I tried running running above code under linux root user (such as php file-name.php) and able to create the file however unable to read source file:

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

I am getting a 403 error. I am very confused with what is going on with this Linux Centos machine. Like i posted earlier in this Centos box i am having problem of Session variables return empty between submit of same page. Any help is appreciated.

Community
  • 1
  • 1
user914425
  • 16,303
  • 4
  • 30
  • 41
  • 1
    @user914425 It could be something to do with your file permission. Try `chmod 777 -R /var/www/vhosts/domain.com/httpdocs/temp/` and try again. Switch the privileges to more secure once you find the problem – Jaspreet Chahal Feb 22 '12 at 03:26
  • let me change to folder permission to 777. – user914425 Feb 22 '12 at 17:14

1 Answers1

4

Why not simply do?:

<?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));
?>
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106