Question

I am trying to create and change the ownership of a file in windows environment ( WAMP). My files are as below :

<?php
$my_file = 'myfile.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
$path = "c:\wamp\www\\".$my_file;
$user_name = "Nitish D";
chown($path, $user_name);
?>

Though the file myfile.txt is created, wheen I checked its details it shows its owner as Administrators. How can I change the owner to my $user_name ?

Was it helpful?

Solution

In case a file that you're trying to change ownership on, belongs to the other user, you can not change it to yourself, unless you run the command as administrator (that user) or root user!

Besides your username contains spaces - that's not allowed on NIX systems. Username should follow the rule:

([a-z_][a-z0-9_]{0,30})

Moreover the username must exist. Try checking if user that you're refering to is really registered:

cat /etc/passwd |grep username
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top