<html><body>
<?php

/* 
Reading files.
Reading the file line by line.
Synatx: $s = fgets($file,max_bytes_plus_1)
fgets reads an entire line (the newline character is 
consumed and it's part of the read string) and assigns it to 
$s$. It reads until it encounters a newline character, the end 
of file, or until it reads max_number_bytes bytes from the file.

You my drop the second argument when you call the function.

Here you can do without a priming read.
*/

echo "_SERVER['DOCUMENT_ROOT'] = {$_SERVER['DOCUMENT_ROOT']} <P>";
//$_SERVER['DOCUMENT_ROOT']}/../temp/abc.txt
echo " __FILE__ = ",  __FILE__, "<P>";

// Reading from a file
if (file_exists('/home/abu-jeib/temp/abb.txt'))
{
// Try to open the file
@ $f = fopen('/home/abu-jeib/temp/abc.txt' /*file*/,'rb' /*file mode*/);
/* 
- Many function are overloaded and take more/less arguments than we use.
- When u use backslashes in the path (for windows), 
you need to write two backslashes isntead of one.
- Relative paths better than absolute.
- Avoid world writable files and directories.
- Do not have world writable files and directories 
in your public directory.
- Use b (for binary) if the system differentiates between binary and 
text files. Windows does, Unix does not.
- You can include html/ftp addresses for files isntead of path
- Domain names are case insensitive, but the path and the file name may 
be case sensitive.
*/

if (!$f) // If u don't succeed
{
	echo "ERROR: file can't be opened.<P></body></html>\n";
	exit;
}
else 
/* If succeeds (note that there is no need for else here because of exit above */
{
	echo "Name, Grade<P>\n";
	$s = fgets($f,10000); // Read a line (priming read)
	// $k =filesize('/home/abu-jeib/temp/abc.txt');
	// Replace 10000 by $k.

	while (!feof($f))
	{
		echo "$s<BR>\n";
		$s = fgets($f,10000); // Read a line
	}

	fclose($f); // close the file
}
echo "<P>Now read the whole file:<P>";
readfile('/home/abu-jeib/temp/abc.txt');

}
else
	echo "<P>File does not exist.<P>\n";
?>
</body></html>

<!-- 

/* Here is the procedure of how to read the file line by line
and display it as it's without using comments.
*/

<html><body>
<?php

@ $f = fopen('/home/abu-jeib/temp/abc.txt' /*file*/,'rb' /*file mode*/);

if (!$f)
{
        echo "ERROR: file can't be opened.<P></body></html>\n";
        exit;
}

$s = fgets($f);
while (!feof($f))
{
        echo "$s<BR>\n";
        $s = fgets($f);
}

fclose($f);

?>
</body></html>


-->
