PHP File: Retrieving More File Information



PHP File Tips - Part 8: If you want to get some information from a particular file, you can use some function such as filesize(), filetype(), and more. Like this:
<?php
$f = "test.txt";

// file type
$type = filetype($f);
echo "Type is ".$type;

// file size
$size = filesize($f);
echo "Size is ".$size." bytes ";

// writeable?
echo is_writable($f) ? "writable" : "not writable";

// readable?
echo is_readable($f) ? "readable" : "not readable";

// executable?
echo is_executable($f) ? "executable" : "not executable";


?>


Series this article:
PHP File: 3 Way of Reading File
PHP File: Reading File at Particular Lines
PHP File: Reading File at Particular Byte Ranges
PHP File: Checking File or Directory
PHP File: Showing All File in A Directory
PHP File: Showing All Files and Folders in Particular Directory
PHP File: Retrieving File Statistic
PHP File: Retrieving More File Information
PHP File: Counting Lines in a File
PHP File: Counting Characters and Words in File
PHP File: Writing File
PHP File: Locking and Unlocking File
PHP File: Removing Lines From File
PHP File: Inserting Lines into a File


Tag: file Category: PHP Basic Post : April 14th 2008 Read: 2,136 Bookmark and Share

blog comments powered by Disqus