is_writable() function in PHP


The is_writable() function checks whether a file is writeable. It returns TRUE if the file exists and is writeable.

Syntax

is_writable(file_path)

Parameters

  • file_path − The path of the file to be checked.

Return

The is_writable() function returns TRUE if the file exists and is writeable.

Example

 Live Demo

<?php
$file = "one.txt";
if(is_writable($file)) {
   echo ("File is writeable!");
} else {
   echo ("File is not writeable!");
}
?>

Output

File is not writeable!

Let us see another example.

Example

<?php
$file_permissions = fileperms("two.txt");
$res = sprintf("%o", $file_permissions);
$file = "two.txt";
if(is_writable($file)) {
   echo ("File is writeable!");
   echo(“Permission = $res”);
} else {
   echo ("File is not writeable!");
   echo(“Permission = $res”);
}
?>

Output

File is writeable!
Permission: 0777

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

70 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements