目录

PHP ftp_chmod() 函数

❮ PHP FTP 参考

示例

设置文件权限:

<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

$file = "php/test.txt";

// Try to set read and write for owner and read for everybody else
if (ftp_chmod($ftp_conn, 0644, $file) !== false)
  {
  echo "Successfully chmoded $file to 644.";
  }
else
  {
  echo "chmod failed.";
  }

// close connection
ftp_close($ftp_conn);
?>

定义和用法

ftp_chmod() 函数通过 FTP 设置指定文件的权限。

语法

ftp_chmod( ftp_conn, mode, file);

参数值

Parameter Description
ftp_conn Required. Specifies the FTP connection to use
mode Required. Specifies the new permissions.

This parameter 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
file Required. Specifies the file to set permissions on


技术细节

返回值: 成功时为新文件权限,失败时为 FALSE
PHP 版本: 5+

❮ PHP FTP 参考