Home > Article > Backend Development > What should I do if php cannot write files?
php cannot write files because the permissions are insufficient. The solution is to change the permissions of the specified file through the "chmod()" function in php. The syntax of this function is "chmod(file,mode)", and the parameters "mode" indicates new permissions.
Recommended: "PHP Video Tutorial"
chmod() Function changes the specified file permission.
Returns TRUE if successful and FALSE if failed.
Syntax
chmod(file,mode)
Parameters
file required. Specifies the documents to be checked.
mode Required. Specify new permissions.
The mode parameter consists of 4 numbers:
The first number is usually 0
The second number specifies the owner's permissions
The third The first number specifies the permissions of the user group to which the owner belongs
The fourth number specifies the permissions of everyone else
Possible values (if you need to set multiple permissions, please adjust the numbers below Total):
1 = Execute permission
2 = Write permission
4 = Read permission
Instance
<?php // Read and write for owner, nothing for everybody else chmod("test.txt",0600); // Read and write for owner, read for everybody else chmod("test.txt",0644); // Everything for owner, read and execute for everybody else chmod("test.txt",0755); // Everything for owner, read for owner's group chmod("test.txt",0740); ?>
The above is the detailed content of What should I do if php cannot write files?. For more information, please follow other related articles on the PHP Chinese website!