Solved

mkdir using php

Posted on 2007-12-06
9
1,311 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Installer 5 37
OS Selection Menu 1 46
IP 10.0.1.2 / 255.0.0.0 61 55
Extracting content from meta tag PHP MYHTML DOM 3 20
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This article discusses how to create an extensible mechanism for linked drop downs.
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 dynamically set the form action using jQuery.

789 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