PHP chmod() Function

In this chapter you will learn:

  1. What is PHP chmod() Function
  2. PHP chmod() Function Syntax
  3. Parameter for PHP chmod() Function
  4. PHP chmod() Function Return Value
  5. Example - changes permissions of the specified file

Definition

The chmod() function changes permissions of the specified file.

Syntax

PHP chmod() Function has the following syntax.

chmod(file,mode)

Parameter

ParameterIs RequiredDescription
fileRequired.File to check
modeRequired.New permissions.

The mode 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

Returns

Returns TRUE on success and FALSE on failure.

Example


<?PHP/*ja  v  a  2 s  .c om*/
//sets the file to readable, writable, and executable by all users
chmod("/var/www/myfile.txt", 0777);

//sets the file to readable, writable, and executable by owner, 
//and just readable and writable by everyone else.

chmod("/var/www/myfile.txt", 0755);

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

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

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

?>

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP chown() Function
  2. Syntax for PHP chown() Function
  3. Parameter for PHP chown() Function
  4. Return for PHP chown() Function
  5. Example - changes the owner of the specified file
Home » PHP Tutorial » PHP File Functions
PHP basename() function
PHP chdir() function
PHP chgrp() Function
PHP chmod() Function
PHP chown() Function
PHP chroot() Function
PHP clearstatcache() Function
PHP closedir() Function
PHP copy() Function
PHP delete() function
PHP dir() Function
PHP dirname() Function
PHP disk_free_space() Function
PHP disk_total_space() Function
PHP diskfreespace() Function
PHP fclose() Function
PHP feof() Function
PHP fflush() Function
PHP fgetc() Function
PHP fgets() Function
PHP fgetss() Function
PHP file() Function
PHP file_exists() Function
PHP file_get_contents() Function
PHP file_put_contents() Function
PHP fileatime() Function
PHP filectime() Function
PHP filegroup() Function
PHP fileinode() Function
PHP filemtime() Function
PHP fileowner() Function
PHP fileperms() Function
PHP filesize() Function
PHP filetype() Function
PHP flock() Function
PHP fnmatch() Function
PHP fopen() Function
PHP fpassthru() Function
PHP fprintf() Function
PHP fputcsv() Function
PHP fputs() Function
PHP fread() Function
PHP fscanf() Function
PHP fseek() Function
PHP fstat() Function
PHP ftell() Function
PHP ftruncate() Function
PHP fwrite() Function
PHP getcwd() function
PHP glob() Function
PHP is_dir() Function
PHP is_executable() Function
PHP is_file() Function
PHP is_link() Function
PHP is_readable() Function
PHP is_uploaded_file() Function
PHP is_writable() Function
PHP link() Function
PHP linkinfo() Function
PHP lstat() Function
PHP md5_file() Function
PHP mkdir() Function
PHP move_uploaded_file() Function
PHP opendir() Function
PHP parse_ini_file() Function
PHP pathinfo() Function
PHP pclose() Function
PHP popen() Function
PHP readdir() Function
PHP readfile() Function
PHP readlink() Function
PHP realpath() Function
PHP rename() Function
PHP rewind() Function
PHP rewinddir() Function
PHP rmdir() Function
PHP scandir() Function
PHP set_file_buffer() Function
PHP sha1_file() Function
PHP stat() Function
PHP symlink() Function
PHP tempnam() Function
PHP tmpfile() Function
PHP touch() Function
PHP umask() Function
PHP unlink() Function
PHP vfprintf() Function