PHP fopen($url,w)

标签 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 的问题。同一页面的提交之间。如有任何帮助,我们将不胜感激。

最佳答案

为什么不简单地做呢?:

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

关于PHP fopen($url,w),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9388411/

相关文章:

c - 在 C 中使用 #define 值作为函数参数 — 为什么它有效?

c - 错误: No such file or directory

C++ 二进制写入或读取

php - 跨类的 PDO 对象

php - 如何在 PHP 中创建电视指南?

c++ - 从 Windows 网络位置打开文件

c - fprintf() 与 fwrite() 的速度

php - 如何从原始查询中检索结果集作为数组而不是 Laravel 3 中的对象

php - 按日期和时间排序并有限制地获取所有记录

c - 为什么我的程序在读取 txt 文件之前就停止了?