ftp_chmod() function in PHP


The ftp_chmod() function set permissions on a remote file via FTP.

Syntax

ftp_chmod(con,mode,my_file);

Parameters

  • con − The FTP connection

  • mode − The new permissions.

    It 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

  • my_file − The File name

Return

The ftp_chmod() function returns new file permissions on success or FALSE on error.

Example

The following is an example to set file permission by changing the mode −

<?php
   $ftp_server="192.168.0.4";
   $ftp_user="amit";
   $ftp_pass="tywg61gh";
   $myfile = "E:/new/demo.txt";
   $con = ftp_connect($ftp_server);
   $res = ftp_login($con, $ftp_user, $ftp_pass);
   if (ftp_chmod($con, 0755, $myfile) !== false) {
      echo "Mode changed successfully! 
";    } else {       echo "Mode cannot be changed!
";    }    ftp_close($con); ?>

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

55 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements