简体   繁体   English

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

[英]Fixing permissions for writing cUrl output to a text file

I am making a web application that grabs one page from the internet using cUrl and updates another page accordingly. 我正在制作一个Web应用程序,它使用cUrl从Internet抓取一个页面并相应地更新另一页面。 I have been doing this by saving the HTML from cUrl and then parsing it on the other page. 通过从cUrl中保存HTML,然后在另一页上进行解析,我一直在这样做。 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. 我没有将其保存在我的/ public / html文件夹中,因为我不希望该网站的任何用户都能看到它。 I only want them to be able to see the way it's parsed on the site. 我只希望他们能够看到网站上解析的方式。

Here is the cUrl code: 这是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  ; 

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

    $runcode = 1 ; 
}

I am receiving an error at that last '$out = fopen($sourcefile, "w");' 我在最后一个'$ 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. 我最终将文件的权限更改为“ 666”,即“ -rw-rw-rw-”,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM