PHP Get file information related basic functions

Source: Internet
Author: User

<?php
Header (' Content-type:text/html;charset=utf-8 ');
Date_default_timezone_set (' PRC ');
/**
* File information related API
*/
$filename = "./test1.txt";
$filename = "Test";
FileType ($filename): Gets the type of file, returns the type of file
echo ' File type: ', filetype ($filename), ' <br/> ';
FileSize ($filename): Gets the size of the file, returns the bytes
echo ' File size: ', FileSize ($filename), ' <br/> ';
Filectime ($filename): Gets the creation time of the file
Echo ' File creation time: ', Filectime ($filename), ' <br/> ';
Echo ' File creation time is: ', date (' Y year m D Day H:i:s ', Filectime ($filename)), ' <br/> ';
Filemtime ($filename): Modified time of File
echo ' File modification time is: ', date ("Y/m/d h:i:s", Filemtime ($filename)), ' <br/> ';
Fileatime ($filename): Last accessed time for files
The last access time for Echo ' file is: ', date ("Y/m/d h:i:s", Fileatime ($filename)), ' <br/> ';
Echo ' Detect whether the file is readable, writable, executable is_readable (), is_writeable (), is_executable ();
Var_dump (
Is_readable ($filename),
Is_writable ($filename),
Is_writeable ($filename),
Is_executable ($filename)
);
Is_file ($filename): detects if a file is present and the file exists
$filename = './test1.txt ';
$filename = './test2.txt ';
Var_dump (Is_file ($filename));

/**
* PathInfo (): File path Related information
*/
$filename = "./test1.txt";
$pathinfo =pathinfo ($filename);
Print_r ($pathinfo);
/*
Array
(
[DirName] =.
[BaseName] = Test1.txt
[Extension] = txt
[FileName] = Test1
)
*/
echo ' File extension: ', PathInfo ($filename, pathinfo_extension), ' <br/> ';
Echo ' $filename =__file__;
echo $filename;

Echo PathInfo ($filename, Pathinfo_dirname), ' <br/> ';
Echo PathInfo ($filename, Pathinfo_basename), ' <br/> ';
Echo PathInfo ($filename, pathinfo_extension), ' <br/> ';
Echo PathInfo ($filename, Pathinfo_filename), ' <br/> ';
BaseName (): Returns the file name portion of the path
Echo basename ($filename), ' <br/> ';

Echo basename ($filename, '. php '), ' <br/> '; The file name part of the return path does not contain the. php suffix
DirName (): Returns the path part of the file name
echo dirname ($filename), ' <br/> ';
File_exists (): detects whether a file or directory exists




PHP Get file information related basic 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.