PHP file Property related functions

Source: Internet
Author: User
Tags echo date

<meta charset= "Utf-8" >
<?php
function to get file attributes
function Getfilepro ($filename) {
Detects if a file exists
if (file_exists ($filename)) {
echo "This file exists <br>";

Detect if it is a directory
if (Is_dir ($filename)) {
echo "This is a catalogue <br>";
}

Detect if it is a file
if (Is_file ($filename)) {
echo "This is a file <br>";
FileSize () only returns the number of bytes
echo "File Size:". Tosize (FileSize ($filename)). " <br> ";
}

Get file permissions
Detect whether it is readable
if (is_readable ($filename)) {
echo "Document readable <br>";
}

if (is_writable ($filename)) {
echo "File writable <br>";
}

if (is_executable ($filename)) {
echo "File executable <br>";
}

Creation time
echo Date ("Y-m-d h:i:s", Filectime ($filename)). " <br> ";
Access time
echo Date ("Y-m-d h:i:s", Fileatime ($filename)). " <br> ";
Modification time
echo Date ("Y-m-d h:i:s", Filemtime ($filename)). " <br> ";

} else {
echo "This file does not exist <br>";
}
}
Getfilepro ("Fengge.txt");

File size conversion function
function Tosize ($size) {
$s = $size;
$DW = "";
2 of the 40 parties, 1024 of the 2-time Square
if ($size > Pow (2, 40)) {
$s = $size/pow (2, 40);
$DW = "TB";
} elseif ($size > Pow (2, 30)) {
$s = $size/pow (2, 30);
$DW = "GB";
} elseif ($size > Pow (2, 20)) {
$s = $size/pow (2, 20);
$DW = "MB";
} elseif ($size > Pow (2, 10)) {
$s = $size/pow (2, 10);
$DW = "KB";
}else {
$s = $size;
$DW = "Types";
}

return $s. $dw;
}

Get the type of file
function Getfiletype ($filename) {
Fifo,char,dir,block,link,file
Switch (filetype ($filename)) {
Case ' dir ':
echo "This is a catalogue <br>";
Break
Case ' char ':
echo "This is a character device <br>";
Break
Case ' block ':
echo "This is a block device <br>";
Break
Case ' file ':
echo "This is a file <br>";
Break
Case ' link ':
echo "This is a link <br>";
Break
Default
echo "Last known type <br>";
}
}
Get the type of file
Getfiletype ($filename);

PHP file Property related functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.