PHP chmod() Function

PHP chmod Function


Definition :

The chmod() function in PHP is an inbuilt function which is used to change the mode of a specified file to a specific mode given by the user.

Syntax

    chmod(filemode)

Parameter 
Parameter Description
file Required. Specifies the path to the file
mode Required. Specifies the new permissions.

The mode parameter consists of four numbers:

  • The first number is always zero
  • The second number specifies permissions for the owner
  • The third number specifies permissions for the owner's user group
  • The fourth number specifies permissions for everybody else

Possible values (to set multiple permissions, add up the following numbers):

  • 1 = execute permissions
  • 2 = write permissions
  • 4 = read permissions

Example of chmod() Function: