Create a directory in php


 

Create a directory in php

You will learn here about creating a directory in php.

You will learn here about creating a directory in php.

Creating a directory in php

In  this example, you will learn to create a form in HTML and call php action function of creating directory in HTML form.

For this, first create an action form in HTML and call the php function in the form to create a directory. In PHP, you can create a directory using mkdir() function, and apply it into printing in the HTML form. See the example:

The PHP Code

<?php
if($_POST["create"]){ 
$name=$_POST["destination"];
$uploaddir = $name;
mkdir($uploaddir,0777);
print "created";
}?>

The HTML Form

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Create Directory</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>

Ads