Search This Blog

Showing posts with label references. Show all posts
Showing posts with label references. Show all posts

scandir() in php

scan.php :

<?php
@print_r(scandir("send"));
?>


output :

Array ( [0] => . [1] => .. [2] => send_vard.php [3] => send_vcard_sms.html [4] => sendsms.html [5] => sendsms.php [6] => smser.php )

reset a directory with rewinddir() in php

 rewinddir.php :

<?php

//Open send directory
if(@$dir = opendir("send"))
{

//List files in send directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "<br />";
}

//resets the directory stream
rewinddir($dir);

//to check for changes

closedir($dir);
}
else
{
echo 'directory not opened';
}
?>

outputs :
 1)
directory not opened

2)


filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

readdir() in php

<?php
//Open send directory

if(@$dir = opendir("send"))

{//List files in send directory

while (($file = readdir($dir)) !== false)

{

echo "filename: ". $file ."<br />";

}

closedir($dir);

}

else

{

echo 'directory not opened';

}

?>

outputs :
 1)
directory not opened

2)
filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

opens a directory with opendir() in php

open.php :

<?php
//Open send directory
if(@$dir = opendir("send"))
{
//List files in send directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "<br />";
}
closedir($dir);
}
else
{
echo 'directory not opened';
}
?>

output :
 1)
directory not opened

2)
filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

current directory with getcwd() in php

getcwd.php :

<?php
echo getcwd();
?>

output :

E:\xampp\htdocs\1

open files in a directory with dir() in php

<?php
//Open send directory
if(@$dir = @dir("send"))
{
//List files in send directory
while (($file = $dir->read()) !== false)
{
echo "filename: " . $file . "<br />";
}
$dir->close();
}
else
{
echo 'directory not opened';
}
?>

output :
 1)
directory not opened

2)
filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

note :
"send" is a directory name

getcwd() and chdir() in php

<?php

//to Get current directory

echo '<br>current directory<br> '.getcwd()."<br />";

//Change to send directory

if(@chdir("send"))
echo '<br>directory changed to<br> '.getcwd();
else
echo '<br>directory not changed<br>';

?>

output :

current directory
C:\xampp\htdocs\1

directory changed to
C:\xampp\htdocs\1\send

when opendir() using it close with closedir() in php

closedir.php :

<?php

//Open send directory
if(@$dir = opendir("send"))
{
echo '<br>dir opened<br>';

//List files in send directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "<br />";
}
closedir($dir);
echo '<br>dir closed<br>';
}
else
echo 'directory not opened';
?>
=========================================
outputs :
 1)
directory not opened

2)
dir opened
filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

dir closed



Share Links

Related Posts Plugin for WordPress, Blogger...