[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1322
  • Last Modified:

mkdir using php

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
subl1m1nal
Asked:
subl1m1nal
  • 4
  • 4
1 Solution
 
nizsmoDeveloperCommented:
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
 
nizsmoDeveloperCommented:
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
 
steelseth12Commented:
<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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
subl1m1nalAuthor Commented:
What's the significance of the \ (forwardslash)?
0
 
nizsmoDeveloperCommented:
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
 
subl1m1nalAuthor Commented:
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
 
nizsmoDeveloperCommented:
did the above work? i think you missed a \,

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

should be:
$mkdir = "mkdir \\\\server\\share\\" . $username;
0
 
subl1m1nalAuthor Commented:
Aboved worked fine.  This is how i understand it.  3 slashes, first one to realse, the other two for UNC name.
0
 
subl1m1nalAuthor Commented:
Nizsmo brings his A game once again for PHP stuff.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now