mkdir Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

mkdir Script

Post by dmallia »

I did a script to make a new folder.

mkdir.php

Code: Select all

<?php
if (isset($_POST['mkdir']))
	{
		mkdir ("test/", 0700);
	}
?>
newfolder.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
	<form action="" method="post" enctype="multipart/form-data" id="uploadfile">
        <input type="submit" name="mkdir" id="mkdir" value="New Folder" >
    </form>
<?php include('mkdir.php'); ?>
</body>
</html>
Now I would like to do a text box so the user enters a name and the script will make the folder's name that the user wanted. Any one knows how i can do it? Thanks
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: mkdir Script

Post by mikeashfield »

Code: Select all

// The HTML file that the user enters the dir name into.
<html>
<head>
<title>Folder Creation Form</title>
</head>
<body>
<form action=""http://127.0.0.1/create_dir.php" method="post">  //Give the file path here
<input type="text" name="dir_name">
<input type="submit" value="Submit" name="Submit">
</form>
</body>
</html>

//The backend PHP that will process it!
<?php
if (isset($_POST['dir_name'])) {
    $dir_name = $_POST['dir_name'];
    if (preg_match("^[^\\\/\?\*\"\>\<\:\|]*$", $dir_name)) {
        mkdir($dir_name, 0700);
        echo "Folder ".$dir_name." created successfully!";
    }
    else {
        echo "Invalid folder name, please try again!";
        }   
}
else {
    echo "You must provide a folder name to continue.";
}
?>
Post Reply