Usefully functions for working with files and/or directories
Basename Function
This function is used for returning the base name of a file or directory. The function response will be given in a string. This function has two string parameters. The first represent the path to a file or a directory and the second (optional) represent the file suffix. Here is an example of using this function:
$path= "c:test.html"; echo "The file name with suffix:<BR>"; echo basename ($path) ."<BR>"; echo "The file name without suffix : <BR>" ; echo basename($path,".html") ;
Dirname Function
This function returns the name of a parent directory of a file or directory in a string. The function has only one string parameter which represent a path to the file or directory. Look at the example for a better understanding:
$path = "c:test.html";echo "The parent directory for ";echo $path." is ".dirname ($path) ;
Pathinfo Function
This function is used for displaying information about a path towards a file or a directory. This function accept as a parameter a string which represent the path to the file or the directory. The function returns an array with strings and contains the elements: ” dirname “, “basename” and “extension”. The elements dirname and basename has the same values with the result of the earlier functions and the element extension contains the file extension. See the example:
$path = "c:test.html";$info = pathinfo ($path) ;echo "Inform $path:<BR>";echo "Director: "; echo $info["dirname"] ."<BR>"; echo "Nume fisier: "; echo $info["basename"] ."<BR>"; echo "Extensie: "; echo $info["extension"] ."<BR>";
File_exists Function
We use this function when we want to see whether one file exists or not on the disk. This function has one parameter, the file name, for which we want too know whether exists or not on the disk. The function return TRUE in case of success and FALSE if the file isn’t find.
Copy Function
If we want to copy a file we should use the copy function. The first parameter of the function represent the name of the source file and the second the name of the destination file. The function return the TRUE value in case of success and FALSE otherwise.
Rename Function
Use this function if you want to rename a file. It has two parameters: the first represent the file name and the second represent the new name for the file. The values returned by the function can be: TRUE in case of success and FALSE otherwise.

RSS/XML