Share on Google+Share on Google+

Creating a File in the directory.

Advertisement
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>

Advertisements

Posted on: July 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.