Home >>Advance PHP Tutorial >PHP File Handling
The file system functions allow you to access and manipulate the file.
file system provides a concept to start a specific data using different types of file format.
That means file gives us linear type database concept.
There is no any type of relations will be found with value because it doesn't support RDBMS concept.
Through this concept you will retrieved data from disk files, XML documents and many other data sources.
Files In a computer, a file system (sometimes written filesystem) is the way in which files are named and where they are placed logically for storage and retrieval.
The DOS, Windows, OS/2, Macintosh, and UNIX-based operating systems all have file systems in which files are placed somewhere in a hierarchical (tree) structure.
A file is placed in a directory (folder in Windows) or sub-directory at the desired place in the tree structure.
touch( ) function is used to create a file Syntax
<?php touch("fileName with extension"); ?>
Eg
<?php //create a ms word file touch("resume.doc"); //create text file touch("data.txt"); //create pdf file touch('corephp.pdf'); ?>
unlink( ) function is used to delete a file Syntax
<?php unlink("fileName with extension"); ?>
Eg
<?php //delete resume word file unlink("resume.doc"); //delete text file unlink("data.txt"); //delete pdf file unlink('corephp.pdf'); ?>
copy( ) function is used to copy file Syntax
<?php copy("source file with extension","destination fileName with same extension"); ?>
Eg
<?php //copy resume doc copy("resume.doc","Update resume.doc"); //copy text file copy("data.txt","update data.txt"); ?>
rename( ) function is used to rename file. Syntax
<?php rename("old fileName with extension","New fileName with same extension"); ?>
Eg
<?php //rename resume doc rename("resume.doc","Update resume.doc"); //rename text file rename("data.txt","update data.txt"); ?>
file_exists( ) function is used to check file or directory existence. Syntax
<?php //check file existence file_exists("fileName with extension"); // OR //check directory extistence file_exists("directory name"); ?>
Eg
<?php //check file existence echo file_exists("Update resume.doc"); ?>
filesize( ) function is used to check file size. Syntax
<?php filesize("fileName with extension"); ?>
Eg
<?php //check file size echo filesize("Update resume.doc")." Bytes"; ?>
realpath( ) function is used to check real path of the file. Syntax
<?php realpath("fileName with extension"); ?>
Eg
<?php //check real path of the file echo realpath("Update resume.doc"); ?>