Issue
<?
if(isset($_POST['Submit']))
{
$password=$_POST['newpwd'];
if(!empty($password))
{
$old_file = "password.txt";
chmod($old_file,0777);
$fh = fopen($old_file, 'w') or die("Can't open file");
fwrite($fh,$password);
fclose($fh);
header("location:index.php");
}
else
{
echo "Please enter a valid password!";
}
}
?>
Above code is used to reset the password. I am getting error "Can't open file" when change the password. Also the chmod operation is not working. The file permission is given below:
-rwxr-xr-x 1 root root 4 Mar 5 13:55 password.txt
I have tried unlink to delete the text file, it also failed.
The above code is working when I delete the text file manually, and then set the file permission to 777.
Any help should be appreciated!
Solution
The script is owned by root
and is writable by the owner only. This means than no one else than root
can change its permissions. You'll have to sudo chown
or sudo chmod
and change the owner or the permissions of the file manually.
Answered By - Tchoupi Answer Checked By - Mildred Charles (WPSolving Admin)