Creating a Function That Performs Multiple File Tests : is_dir « File Directory « PHP






Creating a Function That Performs Multiple File Tests

 
<?php
function outputFileTestInfo( $file ) {
  if ( ! file_exists( $file ) ) {
    print "$file does not exist<br/>";
    return;
  }
  print "$file is ".(    is_file( $file )?"":"not ")."a file<br/>";
  print "$file is ".(    is_dir( $file )?"":"not ")."a directory<br/>";
  print "$file is ".(  is_readable( $file )?"":"not ")."readable<br/>";
  print "$file is ".(  is_writable( $file )?"":"not ")."writable<br/>";
  print "$file is ".( is_executable( $file )?"":"not")."executable<br/>";
  print "$file is ".( filesize($file))." bytes<br/>";
  print "$file was accessed on " . date( "D d M Y g:i A", fileatime( $file ) )."<br/>";
  print "$file was modified on " . date( "D d M Y g:i A", filemtime( $file ) )."<br/>";
  print "$file was changed on  " . date( "D d M Y g:i A", filectime( $file ) )."<br/>";
}
?>
<html>
<head>
<title>Multiple File Tests</title>
</head>
<body>
<div>
<?php
outputFileTestInfo( "test.txt" );
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.is_dir() function verifies that the file is a directory
2.Is a directory
3.Working with Directories