Home Tutorial Php Examples Creating a File in the directory.

 
 

Creating a File in the directory.
Posted on: July 30, 2009 at 12:00 AM
In this example you will learn about creating a File in the directory.

Creating a file using HTML form action

In this example, you will learn to make a query form asking to to create a file in PHP. You will have to write the codes for HTML and PHP. 

First create a HTML form, then call the action form of PHP code in the form.

for creating a file in PHP, first declare a file name, define the path of destination where the file has to created. 

Print the file name and end the php cide.

 Example:

<?php
if($_POST["create"]){ 
$name=$_POST["destination"];
$filename=fopen($name,"x") or exit("File Not Created.");
print "created";
}?>

Creating an action form in HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Create File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body > 
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<table style="border:1px solid #CCCCCC; background-color:#F0F0F0; font-family:verdana; font-size:12px" cellpadding="5" cellspacing="2" width="600px"> 
<tr>
<td><strong>Location</strong></td>
<td><input type="text" id="destination" name="destination"></td>
</tr>
<tr>
<td> </td><td><input type="submit" name="create" value="Create"/></td> 
</tr>
</table>
</form>
</body>
</html>

Related Tags for Creating a File in the directory.:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.