为什么两个不同的所有者为posix_getpwuid(fileowner($ file))在同一目录下,这是什么意思?

时间:2013-05-19 15:00:47

标签: php file-io

我有托管公司的共享虚拟Linux托管,我知道只使用CPANEL,我不知道使用CLI。最近由主机向PHP 5.2迁移到PHP 5.3.2会导致在目录中使用file_put_contents时写入文件的权限被拒绝错误。所以我想以我的身份尝试一些调试工作

// Assume my file is 
// here /home/myhostaccount/public_html/mytest where mytest is 755
// Assume migrated.log exists in the above directory and migrated.log is 644

$file1 = "migrated.log" // this is migrated file which is denied write
$file2 = "dummytest.log"    // this file I created for debug, it allows write

writeme($file1,"This file existed before in 5.2 and was writeable, but fails to do a write after migration  "); 
  // permission denied error failed to write BUT works if file forced to 646

writeme($file2,"This is created file by Me for Debugging ");    
  // works - writes just for the default 644

function writeme($file ,$data) {
  $result = file_put_contents($file , $data, LOCK_EX);
  if ($result === false) {
    echo "failed to write to $file";  echo "<br/>";
   }else{
    echo "successfully written $result bytes to $file <br/>";
  } 
 }

接下来我想我会检查文件所有者,因此

 print_r(posix_getpwuid(fileowner($file1)));
 echo "<br/><br/>";
 print_r(posix_getpwuid(fileowner($file2)));

我输出为

Array ( [name] => myhostaccount [passwd] => x [uid] => 1083 [gid] => 1083 [gecos] => [dir] => /home/myhostaccount [shell] => /bin/bash ) 

Array ( [name] => nobody [passwd] => x [uid] => 99 [gid] => 99 [gecos] => Nobody [dir] => / [shell] => /sbin/nologin )

首先,我不是一个很好的管理员来理解这个完整的输出,但我惊讶为什么两个不同的东西

我的问题是

a)为什么同一目录中的文件将作为不同的所有者运行1)myhostaccount 2)nobody

b)为什么没有人能够使用644成功写入而myhostaccount失败但只能用646写入

c)问题出在哪里?在我身边....或者......在主持方面

d)如果必须在我身边修好我应该做的事情,或者与他们在一起我应该让他们去做什么

请帮助。

此致

1 个答案:

答案 0 :(得分:0)

唯一的原因可能是,其中一个文件已经存在,而另一个文件是由创建的