使用php确定文件是否是系统文件,以及文件的所有者


Determine if file is a system file or not, as well as owner of the file using php

我正在尝试确定一种方法,如何确定一个文件是系统文件还是不使用php。我还想找出文件的所有者和所有者的域。

我尝试了不同的方法来确定文件是否是系统文件,即is_file()fileperms()。接下来,我计划围绕文件名构建函数,如果文件的扩展名为.ini.db.tmp等,或者文件名以"`"开头,则该函数将返回true。如果有人对此有更好的想法,请告诉我。

此外,我正在努力找出文件的所有者和所有者的域,如"NTRSK'USER1",为此我尝试了

$stat = stat($file);
// returns 0 always   
echo(posix_getpwuid($stat['uid']));
// got fatal error 'undefined function posix_getpwuid()'

我也厌倦了fileowner($file);// returned 0,我想要像"NTRSK'USER1"一样的东西。

如果您在Linux 上,则应该使用命令行执行

<?php
$output = shell_exec('ls -lh'); <-- for an example
echo "<pre>$output</pre>";      <-- use the output value to determine file status or owner depending on which command you're using. 
?>