在 Windows 上使用 PHP 读取文件和目录所有者 [英] Reading file and directory owner using PHP on the Windows

查看:49
本文介绍了在 Windows 上使用 PHP 读取文件和目录所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 Windows 上的 PHP 和 xampp 服务器的 Intranet 项目.该 Intranet 项目具有带表的数据库,我在其中存储文件和文件夹的扫描磁盘驱动器信息.我使用简单的 windows 命令 dir "$directory_path"/Q/T:C 来获取信息.

I have an intranet project based on the PHP and xampp server on the Windows. That intranet project have database with table where I store scanned disc drive informations of files and folders. I using simple windows command dir "$directory_path" /Q /T:C to get informations.

之后,我使用正则表达式来匹配和解析该信息以分隔日期、时间、权限和目录名称,如本例所示:

After that I use regex to match and parse that info to separate date, time, permission and dir name like on this example:

目录解析的示例正则表达式

类似于这个例子:使用 PHP 在 Windows 中获取文件所有者

这个工作正常,但有时文件所有者名称真的很长并且被命令行剥离.在这种情况下,我无法读取全名并且功能已损坏.

This working fine but sometimes file owner names are realy long and was stripped by command line. In that case I can't read full name and functionality is broken.

现在我正在寻找另一种解决方案.

Now I searching for another solution.

我的 PHP 也安装了 php_com_dotnet.dll 扩展,我在代码的某些部分使用了 COM() 类.

My PHP have instaled also php_com_dotnet.dll extension and I using COM() class in some part of code.

我的主要问题是:

-我可以使用 COM() 类来获取真实的文件信息并避免使用 shell 命令进行文件搜索和列表吗?

-Can I use COM() class to get real file informations and avoid shell commands for the file search and listings and how?

-是否有其他扩展名、shell 命令或第三种我可以用来获取文件/文件夹所有者的东西?

-Is there some another extension, shell command or something 3rd what I can use to get file/folder owners?

注意:我只需要在数据库中读取和索引,不需要更改权限或所有权.

NOTE: I need this only for the reading and indexing in the database, don't need to change permissions or ownership.

推荐答案

我找到了使用 PHP 类的简单解决方案 COM()IADsSecurityUtility::GetSecurityDescriptor 方法.

I find simple solution for this using PHP class COM() and the documentation of the IADsSecurityUtility::GetSecurityDescriptor method.

PHP 中的代码如下所示:

The code in PHP looks like this:

$path = 'D:\Some File\Some Another File\document.doc'; // File or dir path
$su = new COM("ADsSecurityUtility"); // Call interface
$securityInfo = $su->GetSecurityDescriptor($path, 1, 1); // Call method
echo $securityInfo->owner; // Get file owner

就是这样.

COM 函数仅适用于 Windows 版本的 PHP.

.Net 支持需要 PHP 5 和 .Net 运行时.

.Net support requires PHP 5 and the .Net runtime.

自 PHP 5.3.15/5.4.5 起,此扩展需要 php_com_dotnet.dll要在 php.ini 中启用才能使用这些功能.以前的 PHP 版本默认启用这些扩展.

As of PHP 5.3.15 / 5.4.5, this extension requires php_com_dotnet.dll to be enabled inside of php.ini in order to use these functions. Previous versions of PHP enabled these extensions by default.

您负责安装对各种 COM 对象的支持

这篇关于在 Windows 上使用 PHP 读取文件和目录所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆