Category Archives: PHP-File and Folder Functions

PHP-file_put_contents()

The file_put_contents() filesystem function in PHP will write string data to a file. It works the same as if you were to use fopen(), fwrite(), and fclose() together to write data to a file. The file will be created if the output file does not exist yet, and if it already exists it will be overwritten.
Here is the Example

OUTPUT
file testing
If you would like to append to existing data in a file that already exists you can use the third parameter for this function.


file testing ,this content is for appendng.

PHP-file_get_contents()

The file_get_contents() filesystem function in PHP will read the contents of a target file and set the contents into a string.

Learn HTML

PHP-file_exists()

The file_exists() filesystem function in PHP will let you know if a target file or directory folder exists or not by returning “TRUE” if it is found, and “FALSE” if it is not found.
Here is the Example:
>

OUTPUT:
That file exists.

PHP-dirname()

The dirname() file system function in PHP will return the parent folder’s path. This function will accept one parameter which is the path to a folder or file.
Here is the Example


OUTPUT

project/filename/mp3

PHP-copy()

The copy() file system function in PHP will make a copy of a file that you specify on the server, It will place the new copy where you specify with a name you give it. This function traditionally takes two parameters with the first being the file to copy, and the second parameter is the path and file name of the copy you are creating.
Here is the Example:
Tips and Notes

Note: If the destination file already exists, it will be overwritten.
Example

The output of the code above will be:
1