Make your own free website on Tripod.com

Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

Testing with stat()

stat() is as easy to use as the other file testing functions but is not as straightforward. This is because it returns an array. The returned array has the following data:

0   device
1   inode
2   inode protection mode
3   number of links
4   user id of owner
5   group id owner
6   device type
7   size in bytes
8   time of last access
9  time of last modification
10  time of last change
11  blocksize for filesystem I/O
12  number of blocks allocated 

The items marked in red are NOT available on a Windows system. Other options like user id and group id are also not relevant on Windows 9x (this is a single-user OS. 'member?)

This function is as you can see very comprehensive. It returns useful information about the specified files. I executed the following code fragment on a Windows system ...

<?php
 $file2open = "./nt.txt";
 $fileStat = stat($file2open);
 $totItems = sizeof($fileStat);
 $desc = array("device","inode","inode protection mode","number of links",
    "user id of owner","group id owner","device type","size in bytes",
    "last access","last modification","last change","blocksize", 
    "number of blocks");
			   
 for($counter=0; $counter< $totItems; $counter++){
     print "<p>$desc[$counter] is <b>$fileStat[$counter]";
 }
?>

... and it produced the following output on my computer:

device is 2
inode is 0
inode protection mode is 33206
number of links is 1
user id of owner is 0
group id owner is 0
device type is -1
size in bytes is 74
last access is 991688400
last modification is 990707584
last change is 990707571
blocksize is -1
number of blocks is -1

Notice items 6, 11 and 12 (counting from zero) are hereby set to -1. This is because they are not supported on the Windows system on which I executed the script.

<< Testing Files | Directories >>

JamHitz Productions