by Frost

Introduction
Recently I had an inquiry about how I would go about creating a directory in a PHP script using a FORM with POST / GET data. Creating a Directory from a PHP script using PHP is not all that easy and should be done with caution, as you want to make sure that you validate the input and prevent un-wanted characters from being used to create a directory. Use this script with caution and I would even go so far as to hiding it behind a User Login script and require a valid user.

The Form
For simplicity we will use a very basic input form to submit POST data to the PHP script (I opted to use POST because it is my preference for a php script like this). You can use GET, just be sure to reflect that in the form and on the PHP script. The components of the PHP script will simply be the <form> tags and 2 input tags (one for directory name and one for submit). Here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**********************
File: createDir.php
Author: Frost
Website: http://www.slunked.com
***********************/
?>
<html>
<head><title>Make Directory</title></head>
<body>
	<h2>Make Directory on Server</h2>
	<form name="phpMkDIRForm" method="POST" action="createDir.php">
	Enter a Directory Name (Alpha-Numeric only): <input type="text" value="" name="dirName" /><br />
	<input type="submit" name="create" value="Create Directory" />
	</form>
</body>
</html>

The form is really straight forward, we will add more to this form onto our next step which is creating the actual PHP script.

© 2012 Help Source for Coders - Get Slunked! Suffusion theme by Sayontan Sinha
Stop SOPA