<html>
<! ChangePermission.php                                       >
<! Chapter 10, Oracle Database XE PHP Web Programming         >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script demonstrates how to read and reset file        >
<! permissions.                                               >
<head>
<title>
  Chapter 10 : ChangePermission.php
</title>
</head>
<body>
<?php
  // Read the parameter from the URL.
  $file = $_GET["p_name"];

  // Check for file before creating it.
  if (!file_exists($file))
    touch($file);

  // Print initial permissions.
  print "Permissions: [".get_permissions($file)."]<br />";

  try
  {
    // Set to all for owner, read and execute for others.
    if (@!chmod($file,0755))
      throw new Exception("Change to ".realpath($file)." disallowed.",1);
  }
  catch (Exception $e)
  {
    print $e->getMessage()."<br />";
  }

  // Print changed permissions.
  print "Permissions: [".get_permissions($file)."]<br />";

  // Get file permissions.
  function get_permissions($file)
  {
    // Declare file permission variable.
    $perms = substr(sprintf('%o',fileperms($file)),-4);

	// Clear the program file statistics.
	clearstatcache();

	// Return current file parameters.
	return $perms;
  }
?>
</body>
</html>