Solved

mkdir using php

Posted on 2007-12-06
9
1,305 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Just about everyone has an old PC laying around.  Ask anyone in the IT industry, whether they are a professional or play in it as a hobby.  From outdated Desktops to cheap "throwaway" laptops, they are all around and not as hard to "fix up" as you m…
This article discusses four methods for overlaying images in a container on a web page
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

11 Experts available now in Live!

Get 1:1 Help Now