PHP | DirectoryIterator isWritable() Function
Last Updated :
07 Mar, 2024
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
$directory = new DirectoryIterator(dirname( __FILE__ ));
foreach ( $directory as $dir ) {
if ( $dir ->isWritable()) {
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
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isWritable()) {
echo $directory ->getFilename() . "<br>" ;
}
$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.
Share your thoughts in the comments
Please Login to comment...