Header ("Content-type", "text/html;charset=utf-8"); /* * Declare a function, pass in the file name to get the files properties * @param string $fileName file name */ function Getfilepro ($fileName) { if (!file_exists ($fileName)) { Echo ' file does not exist '; Return } /* is a normal file */ if (Is_file ($fileName)) { echo $fileName. ' is a file '; } /* is the directory */ if (Is_dir ($fileName)) { echo $fileName. ' is a directory '; } /* Type of output file */ The echo ' file type is: '. Getfiletype ($fileName). ' '; /* File size, conversion unit */ The echo ' File size is: '. GetFileSize (FileSize ($fileName)). ' '; /* File is readable */ if (is_readable ($fileName)) { Echo ' File readable '; } /* File is writable */ if (is_writable ($fileName)) { Echo ' file can be written '; } /* File is executable */ if (is_executable ($fileName)) { Echo ' File executable '; } Echo ' File creation time: '. Date (' Y year M month J Day ', Filectime ($fileName)). ' '; Echo ' File last modified: '. Date (' Y year M-month J-Day ', Filemtime ($fileName)). ' '; Echo ' File last opened: '. Date (' Y year M-month J-Day ', Fileatime ($fileName)). ' '; } /* * Declare a function that returns the file type * @param string $fileName file name */ function Getfiletype ($fileName) { $type = "; Switch (filetype ($fileName)) { Case ' file ': $type. = ' normal file '; break; Case ' dir ': $type. = ' directory file '; Case ' block ': $type. = ' block device file '; Case ' char ': $type. = ' character device file '; Case ' filo ': $type. = ' piping file '; Case ' link ': $type. = ' symbolic link '; Case ' unknown ': $type. = ' Unknown file '; Default } return $type; } /* * Declare a function that returns the file size * @param int $bytes file byte number */ function GetFileSize ($bytes) { if ($bytes >= pow (2,40)) { $return = Round ($bytes/pow (1024,4), 2); $suffix = ' TB '; } else if ($bytes >= pow (2,30)) { $return = Round ($bytes/pow (1024,3), 2); $suffix = ' GB '; } else if ($bytes >= pow (2,20)) { $return = Round ($bytes/pow (1024,2), 2); $suffix = ' MB '; } else if ($bytes >= pow (2,10)) { $return = Round ($bytes/pow (1024,1), 2); $suffix = ' KB '; } Else { $return = $bytes; $suffix = ' B '; } return $return. " ". $suffix; } /* Call the function and pass in the Test.txt file in the test directory */ Getfilepro ('./test/div.html '); ?> |