Jump to content

Archived

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

Gruzin

creat directory

Recommended Posts

hi guys,
I need to creat a directory, I've started from php.net:

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

Hope someone will help, thanks in advance,
George

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
mkdir ( path, mode -> user right, permissions );

[code]<?php

$base = 'test/';

$dir = $_POST['dir']; // make sure you validate this

mkdir ( $base . $dir, 0777 );

?>[/code]


me!

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
This:
[code=php:0]mkdir("test/", $dir);[/code]

Is supposed to be:
[code=php:0]mkdir("test/". $dir);[/code]

Share this post


Link to post
Share on other sites
And again:
[color=red]Warning: mkdir(test/new_dir): No such file or directory in /users/3d_cn~1/html/test/index.php on line 5[/color]

yes Huggie, I've tryed your code to but the result is the same... Don't know what to do, thanks anyway guys!

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.