Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

ftp_chmod()

Example

Adjust file permissions.

<?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);
?>

Definition and Usage

The ftp_chmod() function assigns permissions to a specified file on the FTP server.

Syntax

ftp_chmod(ftp_conn, mode, file);

Parameter Values

 

Parameter

Description

ftp_conn

Mandatory. Specifies the FTP connection to use.

mode

Mandatory. Specifies the new permissions, represented by four digits:

  • The first digit is always zero.
  • The second digit specifies permissions for the OWNER.
  • The third digit specifies permissions for the OWNER’s USER GROUP.
  • The fourth digit specifies permissions for EVERYBODY ELSE.

Possible values (sum these numbers to set multiple permissions):

  • 1 = execute permissions
  • 2 = write permissions
  • 4 = read permissions

file

Mandatory. Specifies the file for which to set permissions.

Technical Details

Return Value:

The updated file permissions on success, or FALSE on failure.

PHP Version:

5+