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

I am making a web application that grabs one page from the internet using cUrl and updates another page accordingly. I have been doing this by saving the HTML from cUrl and then parsing it on the other page. The issue is: I can't figure out what permissions I should use for the text file. I don't have it saved in my /public/ html folder, since I don't want any of the website's users to be able to see it. I only want them to be able to see the way it's parsed on the site.

Here is the cUrl code:

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

And the part where I save the text file:

/*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')."
");
    fclose($tracker);

    $runcode = 1 ; 
}

I am receiving an error at that last '$out = fopen($sourcefile, "w");' part that says:

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

Any ideas?

The issue was with file/folder permissions. I ended up changing the permissions for the file to '666' meaning '-rw-rw-rw-' and it worked.