Jump to content

creat directory


Gruzin

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.