[英]fopen creates files owned by root in php
我正在編寫將Disqus注釋轉換為HashOver系統的代碼,並且我有這樣的代碼:
// $threads is list of threads from disqus api that I cached on disk
foreach ($threads as $thread) {
$dir_name = getSafeThreadName(preg_replace("%^https?://[^/]+%", "", $thread['link']));
$dir = 'threads/' . $dir_name;
if (!is_dir($dir)) {
mkdir($dir);
chmod($dir, 0774);
}
// ...
// $thread_posts are $post that belong to $thread
foreach($thread_posts as $post) {
$xml = new SimpleXMLElement('<comment/>');
// ...
// $name_arr is array of numbers for HashOver comments
$fname = $dir . '/' . implode('-', $name_arr) . ".xml";
$f = fopen($fname, 'w');
fwrite($f, $xml->asXML());
fclose($f);
chmod($fname, 0664);
}
}
它為我的線程中的每個帖子創建了目錄,該目錄使用所有者apache:apache
讀/寫,並且在其中1.xml
具有所有者root:root
1.xml
類的文件
為什么是root:root
? 我如何使其成為apache:apache
?
編輯:
這不是重復的,我不想從root:root
更改對apache:apache
權限,可以使用chown
來完成,但是我想這樣做,所以它首先不要將其更改為root:root
,我也想知道為什么將其更改為root:root
。 這對我來說似乎是php或apache中的錯誤,或者對我而言apache中的某些錯誤配置。 我不認為這是代碼,因為它只是打開,寫入和關閉文件。
不知道為什么,我想知道,但這可以解決問題:
我用這個:
chmod($dir, 0775);
代替:
chmod($dir, 0774);
該目錄對其他人而言不可執行,並且在創建時會使該目錄中的文件歸root擁有。 很奇怪。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.