
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
chmod() function in PHP
The chmod() function changes the file mode. It returns TRUE on success and FALSE on failure.
Syntax
chmod($file_path, file_mode)
Parameters
file_path − Set the path of file or directory to be checked for existence. Required.
file_mode − Set the mode with values. The description of file_mode parameter is shown below
File Mode parameter
Set the file mode with the following four values.
- zero
- permission for owner
- permission for the owner’s user group
- permissions for rest
The following are the values to set multiple permissions. You need to add the following numbers −
- 1 = execute permissions
- 2 = write permissions
- 4 = read permissions
Return
The file_exists() method returns.
- True, on success
- False, on failure
Example
The following is an example that changes the mode for file “one.txt”. This sets read and write permission for owner, nothing for everybody else.
<?php // Setting mode for file // Read and write permission for owner, nothing for everybody else chmod("one.txt",0600); ?>
Let us see another example that changes the file mode for “two.txt”. This sets read and write permission for owner, read for everybody else.
<?php // Setting mode for file // Read and write permission for owner, read for everybody else chmod("two.txt",0644); ?>
Let us see another example that changes the file mode for “three.txt”. This sets all the permissions for owner, read and execute for everybody else.
<?php // Setting mode for file // All the permissions for owner, read and execute for everybody else chmod("three.txt",0755); ?>
Let us see another example that changes the file mode for “four.txt”. This sets all the permissions for owner, read for owner's group.
<?php // Setting mode for file // All the permissions for owner, read for owner's group chmod("four.txt",0740); ?>
Let us see another example that changes the file mode for “five.txt”. This sets all the permissions for owner, read and execute for owner's group.
<?php // Setting mode for file // All the permissions for owner, read and execute for owner's group chmod("five.txt",0740); ?>
- Related Articles
- Setting Permissions with chown and chmod
- How to use chmod recursively on Linux?
- strcmp() function in PHP
- strcoll() function in PHP
- strcspn() function in PHP
- strip_tags() function in PHP
- stripcslashes() function in PHP
- stripos() function in PHP()
- stristr() function in PHP
- stripslashes() function in PHP
- strlen() function in PHP
- strnatcasecmp() function in PHP
- strnatcmp() function in PHP
- strncasecmp() function in PHP
- strncmp() function in PHP
