Jump to content

Recommended Posts

Try this:

[code]<?php
$dir = $_POST['dir']; // directory name from form
mkdir("test/$dir");
?> [/code]

Your code passes the path as the first argument and the directory as the second argument.  They should both be the same (argument one).

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104903
Share on other sites

Now just create a html form with a textfield called dir and submit the form to itself:
[code]<?php
if(isset($_POST['action']) && $_POST['action'] == "Create Directory")
{
    $dir = $_POST['dir']; // directory name from form
    mkdir("test/", $dir);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  New Directory Name: <input type="text" name="dir"><br />
  <input type="submit" name="action" value="Create Directory">
</form>[/code]
Link to comment
https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104905
Share on other sites

[quote author=wildteen88 link=topic=110682.msg447875#msg447875 date=1160131976]
Now just create a html form with a textfield called dir and submit the form to itself:
[code]<?php
if(isset($_POST['action']) && $_POST['action'] == "Create Directory")
{
    $dir = $_POST['dir']; // directory name from form
    mkdir("test/", $dir);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
   New Directory Name: <input type="text" name="dir"><br />
   <input type="submit" name="action" value="Create Directory">
</form>[/code]
[/quote]

Here what I get:
[color=red]Warning: mkdir() expects parameter 2 to be long, string given in /users/3d_cn~1/html/gg/index.php on line 5[/color]
Link to comment
https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104908
Share on other sites

[quote author=Gruzin link=topic=110682.msg447878#msg447878 date=1160132197]
Here what I get:
[color=red]Warning: mkdir() expects parameter 2 to be long, string given in /users/3d_cn~1/html/gg/index.php on line 5[/color]
[/quote]

Did you read my post about the arguments?  Try this:

[code]<?php
if(isset($_POST['action']) && $_POST['action'] == "Create Directory")
{
    $dir = $_POST['dir']; // directory name from form
    mkdir("test/$dir");
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  New Directory Name: <input type="text" name="dir"><br />
  <input type="submit" name="action" value="Create Directory">
</form>[/code]

Huggie
Link to comment
https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104909
Share on other sites

God! I hate this server, php is running in safe mode :(

[color=red]Warning: mkdir(): SAFE MODE Restriction in effect. The script whose uid/gid is 5658/80 is not allowed to access / owned by uid/gid 0/0 in /users/3d_cn~1/html/test/index.php on line 5[/color]

Can I do something except changing this stupid server?
Link to comment
https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104921
Share on other sites

Sorry if I'm off the mark.  The second variable is the permissions, I believe.

Here's some code I use in case it helps ...

$file_loc = $server_dir . 'log' . $svr_dir_delimit . 'knightchat' . $svr_dir_delimit . 'chat.log';
$dir_loc = $server_dir . 'log' . $svr_dir_delimit . 'knightchat';
if (!is_dir($dir_loc))
{ mkdir($dir_loc, 0700); }

I did have issues with writing directories that the script didn't have permissions to create.  It is a matter of working out what credentials the PHP script is running with.  I did this by setting a directory to 777, running the script to create the directory, then I could see what user name and group it created the directory with, by using the ls -la.  Then I tightened the security on the parent directory again.

Re: the safe mode, I think there is no way other than to switch the php.ini file to not operate in safe mode.  I don't think it can be done by a session variable, but I'm no expert.
Link to comment
https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104926
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.