Solved

mkdir using php

Posted on 2007-12-06
9
1,314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 3

Author Comment

by:subl1m1nal
ID: 20423516
What's the significance of the \ (forwardslash)?
0
 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

696 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