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

    Learn programming in R: courses

    $

    Best Python online courses for 2022

    $

    Best laptop for Fortnite

    $

    Best laptop for Excel

    $

    Best laptop for Solidworks

    $

    Best laptop for Roblox

    $

    Best computer for crypto mining

    $

    Best laptop for Sims 4

    $

    Latest questions

    NUMPYNUMPY

    psycopg2: insert multiple rows with one query

    12 answers

    NUMPYNUMPY

    How to convert Nonetype to int or string?

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Javascript Error: IPython is not defined in JupyterLab

    12 answers


    Wiki

    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | cv2.circle () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method