This section contains the detail about File Creation in PHP
File Creation in PHP
In PHP, fopen function is used to open files as well as used to create file, if it does not find the file specified in the function call.
For creating a file, we need to open the file in write mode as given below :
<?php $MyFileName = 'C:\myfile.txt'; $MyFileHandle = fopen($MyFileName, 'w') or die("cant open file"); fclose($MyFileHandle); ?>
Note : We have to tell PHP we are writing to the file, otherwise it will not create a new file.
The fopen function returns a file handle, which will allow us to manipulate the file. We save the file handle into the $MyFileHandle variable to use it in further manipulation of file.
[ 0 ] Comments