Page 1 of 1
Creating a directory
Posted: Tue Nov 28, 2006 7:18 pm
by admaster
Sorry about this, but I'm a newbie at php.
I'm trying to create a type of program that will allow me to input a name in the first page, adn create a directory iwith that name.
This is how far I got.
input.php:
Code: Select all
<html>
<body>
<title>Create User Form (Beta)</title>
</script>
<form name="form1" method="post" action="create.php">
<p>Enter the username you want to create</p>
<p>
<input name="$cuser" type="text" id="$cuser" maxlength="100">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
create.php:
Thanks a lot.
Jcart | Changed thread title appropriately
Posted: Tue Nov 28, 2006 7:21 pm
by evilchris2003
do you mean a file directory
or database table to create login (a guess from your HTML code)
Posted: Tue Nov 28, 2006 7:24 pm
by admaster
I don't want to have a sql database. I want a small page which asks you to input a name of a directory. Then, when pressing submit, the directory is completed. It doesn't work for me.
Posted: Tue Nov 28, 2006 7:26 pm
by evilchris2003
im sorry i really dont understand what you are trying to do
Posted: Tue Nov 28, 2006 7:27 pm
by admaster
Okay. I want a screen that has a box asking for some value. Then, afte rclicking a button, it parses a script, and creates a directory with teh name of what was inputted on the first page. Is it clear now?
Posted: Tue Nov 28, 2006 7:30 pm
by evilchris2003
but what sort of directory there are several ways to interpret this
for example what do you want the directory to do once it is created
Posted: Tue Nov 28, 2006 7:31 pm
by admaster
Nothing. Just create one.
I wnat a file-folder type thingy
Posted: Tue Nov 28, 2006 7:51 pm
by Zoxive
you need a full or absolute path name for mkdir();
example..
Code: Select all
mkdir("/www/htdocs/public_html/home/newfolder/", 0700);
and you can do something like...
Code: Select all
if(mkdir("/www/htdocs/public_html/home/newfolder/", 0700)){
echo 'Success!';
}else{
echo 'Making Directory Failed';
}
Posted: Tue Nov 28, 2006 7:52 pm
by evilchris2003
well im fairly new to PHP and i havent come across it i have googled about a bit to maybe im using the wrong keywords but sorry i cant help
Posted: Tue Nov 28, 2006 7:53 pm
by shoebappa
Hopefully register globals is not on for security reasons. You should use:
Code: Select all
<?
mkdir($_POST["cuser"], 0777);
?>
If the form action was the GET method, you would use the $_GET... Also if you aren't *nix you could prolly use just mkdir($_POST["cuser"]);
also don't use $ in the HTML part!
Code: Select all
<html>
<body>
<title>Create User Form (Beta)</title>
<form name="form1" method="post" action="create.php">
<p>Enter the username you want to create</p>
<p>
<input name="cuser" type="text" id="cuser" maxlength="100">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
Posted: Tue Nov 28, 2006 7:55 pm
by John Cartwright
Hold on a moment there
Firstly let me tell you that we are all volunteers here, and will help those at our own wishes. With that in mind, do you think it's fair to tell us how quickly and important this is that you get it fixed? If it is important then you should considering hiring a professional.
I've already deleted a post, and changed your thread title.. so lets not let this happen again ok?
Now as for your problem, it looks like your server configuration has register globals set to off (which is a good thing). That means that you have to reference global variables (such as form variables) why their global namespace.
I also noticed in your html you are trying to reference a php variable. I don't think you meant to do that so lets go ahead and remove it.
Code: Select all
<input name="$cuser" type="text" id="$cuser" maxlength="100">
becomes
Code: Select all
<input name="cuser" type="text" id="cuser" maxlength="100">
There are some security implications with this.. you should
a) check whether the directory exists or not prior to creating it,
file_exists() may be of interest
b) You should consider creating them the directories in a subdirectory
Code: Select all
mkdir('users/'. $_POST['cuser'], 0777);
c) and lastly you should check whether they are entering legitimate data into the form
empty(),
isset(),
ctype_alpha(),
preg_match() all may be if interest
Posted: Tue Nov 28, 2006 7:59 pm
by shoebappa
Zoxive wrote:you need a full or absolute path name for mkdir();
I think if you don't it makes it in the same directory as the current script...
Edit: Confirmed on PHP 5.1
Posted: Tue Nov 28, 2006 8:01 pm
by Zoxive
shoebappa wrote:Zoxive wrote:you need a full or absolute path name for mkdir();
I think if you don't it makes it in the same directory as the current script...
Yup, you never know where he could be looking, it could acually create it and he could of easily been looking in the wrong folder in the first place. But as it has already been pointed out, he had a '$' which caused the whole mess.
Posted: Tue Nov 28, 2006 8:12 pm
by admaster
Jcart wrote:Hold on a moment there
Firstly let me tell you that we are all volunteers here, and will help those at our own wishes. With that in mind, do you think it's fair to tell us how quickly and important this is that you get it fixed? If it is important then you should considering hiring a professional.
I've already deleted a post, and changed your thread title.. so lets not let this happen again ok?

I'm very sorry. I'm a newbie here. Sorry.
