<html>
<! GetFileByChunks.php                                        >
<! Chapter 10, Oracle Database XE PHP Web Programming         >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script demonstrates how to read a file by chunks      >
<! and then render the contents into a web page.              >
<head>
<title>
  Chapter 10 : GetFileByChunks.php
</title>
</head>
<body>
<?php
  // Set directory and backquote directory delimiters.
  $directory = "C:\\php\\";

  // Set the file name.
  $fname = "php.ini";

  // Declare an array to hold character buffers.
  $contents = array();

  // Check for a valid read-only file handle.
  if ($fp = fopen($directory.$fname,'r'))
  {
    // Read to end-of-file by chunks of 100 characters.
    while (!feof($fp))
      $contents[] = fgets($fp, 100)."<br>";

    // Close the open file handle.
    fclose($fp);
  }

  // Read and print the file by buffer chunks.
  foreach ($contents as $key => $value)
    print $value;
?>
</body>
</html>
