Solved

mkdir using php

Posted on 2007-12-06
9
1,307 Views
Last Modified: 2013-12-13
LOL, it seems like I'm posting for help here everyday.  Here's the problem of the day.

Creating a user works great!  Now my task is to get this code to make a folder.  Eventually, I want to get it to assing permissions from the user this creates to the folder it creates.

Here's the error I'm getting:

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\process.php on line 13
<html>

<body>

<?php

$username = $_POST["username"];

$password = $_POST["password"];
 

$adduser = "net user " . $username . " " . $password . " /add";

$userout = shell_exec($adduser);

echo "Adding User:  {$userout}";
 

$mkdir = "mkdir \\server\share\" . $username;

$mkdirout = shell_exec($mkdir);

echo "Creating folder:  {$mkdirout}";

?>

</html>

</body>

Open in new window

0
Comment
Question by:subl1m1nal
  • 4
  • 4
9 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20422477
Hi sub1m1nal

This should fix it.
<html>

<body>

<?php

$username = $_POST["username"];

$password = $_POST["password"];

 

$adduser = "net user " . $username . " " . $password . " /add";

$userout = shell_exec($adduser);

echo "Adding User:  {$userout}";
 

$mkdir = "mkdir \\server\share\\" . $username;

$mkdirout = shell_exec($mkdir);

echo "Creating folder:  {$mkdirout}";

?>

</html>

</body>

Open in new window

0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20422490
basically this line:
$mkdir = "mkdir \\server\share\" . $username;

the " is getting escaped with \ since they are after each other \", therefore we have to escape the \ but putting double \\.

Hope this helps.
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20422587
<html>
<body>
<?php
$username = $_POST["username"];
$password = $_POST["password"];
 
$adduser = "net user " . $username . " " . $password . " /add";
$userout = shell_exec($adduser);
echo "Adding User:  {$userout}";
 
$mkdir = "mkdir \\\\server\\share\\" . $username;
$mkdirout = shell_exec($mkdir);
echo "Creating folder:  {$mkdirout}";
?>
</html>
</body>
0
 
LVL 3

Author Comment

by:subl1m1nal
ID: 20423516
What's the significance of the \ (forwardslash)?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20423533
it is an escape character. Therefore steelseth's solution is correct, to represent a \ you will need double \\ to escape the escape character.

hope this helps.
0
 
LVL 3

Author Comment

by:subl1m1nal
ID: 20423628
Ah, much help guys.  I appreciate all the experienced programers helping out a programming n00b!  Final code attached below.
<html>

<body>

<?php

$username = $_POST["username"];

$password = $_POST["password"];

 

$adduser = "net user " . $username . " " . $password . " /add";

$userout = shell_exec($adduser);

echo "Adding User:  {$userout}";

 

$mkdir = "mkdir \\\server\\share\\" . $username;

$mkdirout = shell_exec($mkdir);

echo "Creating folder:  {$mkdirout}";

?>

</html>

</body>

Open in new window

0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20423644
did the above work? i think you missed a \,

$mkdir = "mkdir \\\server\\share\\" . $username;

should be:
$mkdir = "mkdir \\\\server\\share\\" . $username;
0
 
LVL 3

Author Comment

by:subl1m1nal
ID: 20452186
Aboved worked fine.  This is how i understand it.  3 slashes, first one to realse, the other two for UNC name.
0
 
LVL 3

Author Closing Comment

by:subl1m1nal
ID: 31413236
Nizsmo brings his A game once again for PHP stuff.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now