File Creation in PHP

File Creation in PHP


Posted in : PHP Posted on : January 4, 2011 at 6:40 PM Comments : [ 0 ]

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.

Download Source Code

 

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics