The DirectoryIterator::isWritable() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item can be written or not.
Syntax:
bool DirectoryIterator::isWritable( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns TRUE if the file/directory is writable, otherwise returns FALSE.
Below programs illustrate the DirectoryIterator::isWritable() function in PHP:
Program 1:
<?php // Create a directory Iterator $directory = new DirectoryIterator(dirname( __FILE__ ));
// Loop runs for each element foreach ( $directory as $dir ) {
// Check for writable element
if ( $dir ->isWritable()) {
// Display the file name
echo $dir ->getFilename() . "<br>" ;
}
} ?> |
Output:
. .. applications.html bitnami.css dashboard favicon.ico geeks.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
Program 2:
<?php // Create a directory Iterator $directory = new DirectoryIterator(dirname( __FILE__ ));
// Loop runs while directory element is valid while ( $directory ->valid()) {
// Check for writable element
if ( $directory ->isWritable()) {
// Display the file name
echo $directory ->getFilename() . "<br>" ;
}
// Move to the next element
$directory ->next();
} ?> |
Output:
. .. applications.html bitnami.css dashboard favicon.ico geeks.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
Note: The output of this function depends on the content of server folder.