3

Provide a path to file, and get its owner username on Windows?

Of course, fileowner is useless here.

Any PECL extensions that can help?

Edit: Alternative that will also work:

Read the summary data from a .DOC file, to retrieve the Author.

Edit 2: Found a solution using COM("word.application"). Any others?

djdy
  • 6,779
  • 6
  • 38
  • 62
  • Please post the solution you found as an answer to this question so that others may benefit. You don't have to mark it as solved, to encourage others to post. – Jim Dec 05 '11 at 19:32

3 Answers3

1

You can accomplish this (for any file of any type) by shelling out to the command line and executing a DIR /Q command on the file:

$output = shell_exec('dir ' . $filepath . '/Q');

$output = explode(' ', $output);

foreach($output as $entry) {
    if(strtoupper($entry) == '{DOMAIN}\\' . strtoupper($loggedInUser)) {
        $owner = str_replace('{DOMAIN}\\', '', $entry);
    }
}

This functions properly only a Windows system while the native PHP function fileOwner functions properly only on a linux system.

Where I work, we have a PHP extension that somehow extracts this information with a single function call but I have no idea how it works.

Mark
  • 861
  • 9
  • 17
1

You could try parsing a System call like System("icacls $file", $return_value) though that only works on windows and is not the cleanest solution

arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
0

I just find solution for this problem. Here is the answer https://stackoverflow.com/a/56458656/2592415

$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
Ivijan Stefan Stipić
  • 6,249
  • 6
  • 45
  • 78