PHP ftp_chmod()Functions


PHP FTP 参考手册Complete PHP FTP Reference Manual

Definition and Usage

The ftp_chmod() function sets permissions for a specified file on the FTP server.

If successful, the function returns the new permissions. If it fails, it returns FALSE and a warning.

Syntax

ftp_chmod(ftp_connection,mode,file)

Parameters Description
ftp_connection Required. Specifies the FTP connection to use.
mode Required. Specifies the new permissions.

The mode parameter consists of 4 numbers:

  • The first number is usually 0
  • The second number specifies the permissions for the owner
  • The third number specifies the permissions for the user group to which the owner belongs
  • The fourth number specifies the permissions for all other people

Possible values (to set multiple permissions, total the numbers below):

  • 1 = execute permissions
  • 2 = write permissions
  • 4 = read permissions
file Required. Specifies the name of the file whose permissions are to be modified.


Example

<?php
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"user","pass");

// Read and write for owner, nothing for everybody else
ftp_chmod($conn,"0600","test.txt");

// Read and write for owner, read for everybody else
ftp_chmod($conn,"0644","test.txt");

// Everything for owner, read and execute for everybody else
ftp_chmod($conn,"0755","test.txt");

// Everything for owner, read for owner's group
ftp_chmod($conn,"0740","test.txt");

ftp_close($conn);
?>


PHP FTP 参考手册Complete PHP FTP Reference Manual Other Extensions