Example 1 — Read the Owner Id
Create a file and print the user id of its owner.
<?php
$file = __DIR__ . '/owner_demo.txt';
file_put_contents($file, 'Hello');
$uid = fileowner($file);
echo "Owner ID: $uid", PHP_EOL;
unlink($file); How It Works
- file_put_contents() creates the file, so it belongs to the user running PHP.
- fileowner() returns the numeric id of that user.
- The id is printed. On a web server it is often the web user, such as 33 for www-data.
- unlink() removes the demo file.

