修复将 cUrl 输出写入文本文件的权限

Fixing permissions for writing cUrl output to a text file

我正在制作一个 Web 应用程序,它使用 cUrl 从 Internet 抓取一个页面并相应地更新另一个页面。我一直在通过从 cUrl 中保存 HTML 然后在另一页上解析它来做到这一点。问题是:我不知道应该对文本文件使用什么权限。我没有将它保存在我的 /public/ html 文件夹中,因为我不希望网站的任何用户能够看到它。我只希望他们能够看到它在网站上的解析方式。

这是 cUrl 代码:

$perfidlist = "" ; 

$sourcefile = "../templates/textfilefromsite.txt";
$trackerfile = "../templates/trackerfile.txt";

//CURL REQUEST 1 OF 2
$ch = curl_init("http://www.website.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
<more cUrl options omitted>
ob_start();
$curl2 = curl_exec($ch);
ob_end_clean();
curl_close($ch);

//WRITING FILES
$out = fopen($sourcefile, "r");
$oldfiletext = fread($out, filesize($sourcefile));
fclose($out);

$runcode = 1  ; 

以及我保存文本文件的部分:

/*only writing a file if the site has changed*/

if (strcmp($oldfiletext, $curl2) !==0)
{
    $out = fopen($sourcefile, "w");
    fwrite($out, $curl2);
    fclose($out);

    $tracker = fopen($trackerfile, "a+");
    fwrite($tracker, date('Y/m/d H:i:s')."\n");
    fclose($tracker);

    $runcode = 1 ; 
}

我在最后一个“$out = fopen($sourcefile, "w");”处收到错误部分说:

Warning: fopen(../templates/textfilefromsite.txt): failed to open stream: Permission denied in /usr/share/nginx/templates/homedir.php on line 72

有什么想法吗?

问题与 file/folder 权限有关。我最终将文件的权限更改为“666”,意思是“-rw-rw-rw-”,它起作用了。