Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

<?
// open file for writing
$myFile = fopen("data.txt","w");


// make sure the open was successful
if(!($myFile))
{
print("file could not be opened");
exit;
}


//use 1K buffer
print(set_file_buffer($myFile, 1024));


for($index=0; $index<10; $index++)
{
// write a line to the file
fwrite($myFile, "line $index\n");
}


// close the file
fclose($myFile);
?>


array stat(string filename)


The stat function executes C's stat function and returns an array. The array contains 13
elements, numbered starting at zero. If the filename argument points to a symbolic link,
the array will reflect the file to which the link points. To get information about the link
itself, use the lstat function. Table 8.7 lists the contents of the array.


<?
/*
* print stat information based on OS
/


// get stat information
$statInfo = stat("data.txt");


if(eregi("windows", $OS))
{
// print useful information for Windows
printf("Drive: %c
\n", ($statInfo[0]+65));
printf("Mode: %o
\n", $statInfo[2]);
print("Links: $statInfo[3]
\n");
print("Size: $statInfo[7] bytes
\n");
printf("Last Accessed: %s
\n",
date("H:i:s F d, Y", $statInfo[8]));
printf("Last Modified: %s
\n",
date("H:i:s F d, Y", $statInfo[9]));
printf("Created: %s
\n",

Free download pdf