Change language

PHP Chmod () function

Syntax:
bool chmod (string $filename, int $mode)
Parameters used: The chmod() function in PHP takes two parameters: filename and mode.
  • $filename : Specifies the file whose permissions need to be changed.
  • $mode : used to specify new permissions. The $mode parameters consist of four numeric values, where the first value is always zero, the second value specifies the owner’s permissions, the third value specifies the group’s permissions owner users, and the fourth value sets the permissions for everyone else. 
    There are three possible values, and the following values ​​can be added to set multiple permissions.
    • 1 = Execute Permissions
    • 2 = Write Permissions
    • 4 = read permissions
  • Return value:returns true on success and false on error.Errors and Exceptions :
  • PHP’s chmod() function does not work for remote files. It only works on files accessible to the server’s file system.
  • If quotes are used around the $mode parameter, such as chmod (file.txt, "0744"), then PHP will perform an implicit conversion to an integer data type.
  • Examples:
    Input: chmod ("gfg.txt", 0600); Output: true Input: chmod ("gfg.txt", 0644); Output: true Input: chmod ("gfg.txt", 0755); Output: true
    The following programs illustrate the chmod() function in PHP:Program 1 :  
    // Read and write owner permissions chmod ( "gfg. txt " , 0600);  
    ?>
    Output:
    true  Program 2 :       
    // Read and write permission for the owner,
    / / and read permission for everyone else chmod ( " gfg.txt " , 0644);  
    ?>
    Output:
    true  Program 3 :       
    // All rights to owner, read and
    // grant permissions for everyone else chmod ( "gfg.txt" , 0755);  
    ?>
    Output:
    true  Link:
    http://php.net/manual/ en / function.chmod.php

    Shop

    Gifts for programmers

    Learn programming in R: courses

    $FREE
    Gifts for programmers

    Best Python online courses for 2022

    $FREE
    Gifts for programmers

    Best laptop for Fortnite

    $399+
    Gifts for programmers

    Best laptop for Excel

    $
    Gifts for programmers

    Best laptop for Solidworks

    $399+
    Gifts for programmers

    Best laptop for Roblox

    $399+
    Gifts for programmers

    Best computer for crypto mining

    $499+
    Gifts for programmers

    Best laptop for Sims 4

    $

    Latest questions

    PythonStackOverflow

    Common xlabel/ylabel for matplotlib subplots

    1947 answers

    PythonStackOverflow

    Check if one list is a subset of another in Python

    1173 answers

    PythonStackOverflow

    How to specify multiple return types using type-hints

    1002 answers

    PythonStackOverflow

    Printing words vertically in Python

    909 answers

    PythonStackOverflow

    Python Extract words from a given string

    798 answers

    PythonStackOverflow

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    606 answers

    PythonStackOverflow

    Python os.path.join () method

    384 answers

    PythonStackOverflow

    Flake8: Ignore specific warning for entire file

    360 answers


    Wiki

    Python | How to copy data from one Excel sheet to another

    Common xlabel/ylabel for matplotlib subplots

    Check if one list is a subset of another in Python

    How to specify multiple return types using type-hints

    Printing words vertically in Python

    Python Extract words from a given string

    Cyclic redundancy check in Python

    Finding mean, median, mode in Python without libraries

    Python add suffix / add prefix to strings in a list

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    Python - Move item to the end of the list

    Python - Print list vertically