Solved

mkdir using php

Posted on 2007-12-06
9
1,316 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
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.

726 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