PHP File Information
From w3cyberlearnings
Contents |
PHP File Information
- Get file information is very important.
- File Size, Access time, update time, and modify time
- File access such file readable, executable, and writable.
List of functions
filectime(filename) ; // file change time fileatime(filename) ; // file access time filemtime(filename) ; // file update time file_exists(filename); // file exists is_executable(filename); // file is executable is_readable(filename); // file is readable is_file(filename); // check it is file file_size(filename); // get file size
Example 1
- Make sure you have create a text file and name it as book.txt.
- Note: When you run this progrma, you will a different result.
<?php $my_file = 'book.txt'; getFileInfo($my_file); function getFileInfo($filename) { if (!file_exists($filename)) { echo "$filename does not exist <br/>"; } $exec_f = (is_executable($filename) ? "yes" : "no"); $write_f = (is_writable($filename) ? "yes" : "no"); $read_f = (is_readable($filename) ? "yes" : "no"); $a_f = (is_file($filename) ? "yes" : "no"); $d_f = (is_dir($filename) ? "yes" : "no"); echo "$filename is .. <br/>"; echo "Executable: " . $exec_f . "<br/>"; echo "Writable: " . $write_f . "<br/>"; echo "Readable:" . $read_f . "<br/>"; echo "Is A file:" . $a_f . "<br/>"; echo "Is A Directory:" . $d_f . "<br/>"; echo "File Change time: " . date("D, Y M d g:i A", filectime($filename)) . "<br/>"; echo "File Access time: " . date("D, Y M d g:i A", fileatime($filename)) . "<br/>"; echo "File Update time: " . date("D, Y M d g:i A", filemtime($filename)) . "<br/>"; echo "File Size: " . filesize($filename) . "bytes or " . (filesize($filename) / 1023) . "M<br/>"; echo "File Permission: " . substr(base_convert(fileperms($filename), 10, 8), 3); } ?>
Output
book.txt is .. Executable: no Writable: yes Readable:yes Is A file:yes Is A Directory:no File Change time: Tue, 2012 May 15 5:27 PM File Access time: Tue, 2012 May 15 5:27 PM File Update time: Tue, 2012 May 15 5:27 PM File Size: 8bytes or 0.0078201368523949M File Permission: 666
Related Links
- PHP File Linux vs. Windows
- PHP File Information
- PHP File Create
- PHP File Close
- PHP File Read
- PHP File Read Reverse