Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

chmod()

Example

Modify the permissions for the file “test.txt”.

<?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);
?>

Definition and Usage

The chmod() function adjusts the permissions of the specified file.

Syntax

chmod(filemode)

Parameter Values

Parameter

Description

file

Mandatory. Specifies the path to the file.

mode

Mandatory. Specifies the new permissions.

The mode parameter is composed of four digits:

  • The first digit is always zero.
  • The second digit defines permissions for the file owner.
  • The third digit indicates permissions for the owner’s user group.
  • The fourth digit specifies permissions for everyone else.

Possible values (combine numbers to set multiple permissions):

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

Technical Details

Return Value:

Returns TRUE upon success and FALSE upon failure.

PHP Version:

4.0+