It opens file or URL
Example
<?php
$fp = @fopen(“test.txt”, “r”);
if ($fp) {
while (($content = fgets($fp, 4096)) !== false) {
echo $content;
}
fclose($fp);
}
?>
It opens file or URL
Example
<?php
$fp = @fopen(“test.txt”, “r”);
if ($fp) {
while (($content = fgets($fp, 4096)) !== false) {
echo $content;
}
fclose($fp);
}
?>
Match filename against a pattern
Example
<?php
$color =”phpcodez.txt”;
if (fnmatch(“*phpcode[zs].txt”, $color)) {
echo “phpcodez”;
}
?>
Output
phpcodez
It can be used to lock the file
Example
<?php
$fp = fopen(“test.txt”, “r+”);
flock($fp, LOCK_EX); // acquire an exclusive lock (writer).
flock($fp, LOCK_SH); // acquire a shared lock (reader).
flock($fp, LOCK_UN); // unlock the file
fclose($fp);
?>
It returns file type
Example
<?php
echo filetype(“test.txt”);
?>
Output
file
It returns file size
Example
<?php
echo filesize(“test.txt”);
?>
Output
31
It returns file permissions
Example
<?php
echo fileperms(“test.txt”);
?>
Output
33279
It returns file owner
Example
<?php
echo fileowner(“test.txt”);
?>
It returns file modification time
Example
<?php
echo date(“D M Y h i s”,filemtime(“test.txt”));
?>
Output
Fri May 2007 03 15 53
It returns file inode
Example
<?php
echo fileinode(“test.txt”);
?>
Output
673771
It returns file group
Example
<?php
echo filegroup(“test.txt”);
?>
Output
1000