Changes

Jump to: navigation, search

PHP, Filesystems and File I/O

354 bytes added, 17:25, 5 June 2007
Accessing File Attributes
PHP provides access to a wide range of file attributes such as when the file was created, whether the file is readable or writeable and the current file size.
The PHP ''stat()'' and ''fstat()'' functions provide a wealth of information about a file. The information is so copious that the results are returned as an associative array. The function take a single argument. ''stat()'' takes a string definingthe poath defining the path to the file. ''fstat()'' takes a file handle returned from an ''fopen()'' function call.
The following table outlines the array values returned by both functions:
<td>blocks<td>Number of blocks allocated</td>
</table>
 
With reference to the above table we can now extarct some information about a file on the file system of our server:
 
<pre>
<?php
 
$results = stat ("/tmp/php_essentials.txt");
 
echo "File size is $results[size]" . "<br>";
echo "File last modifed on $results[mtime]" . "<br>";
echo "File occupies $results[blocks] filesystem blocks" . "<br>";
?>
</pre>

Navigation menu