Jump to content


Photo

creat directory


  • Please log in to reply
9 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 06 October 2006 - 10:42 AM

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

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


Hope someone will help, thanks in advance,
George
I don't need your script, I'll try to write it myself

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 10:50 AM

Try this:

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

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 October 2006 - 10:52 AM

Now just create a html form with a textfield called dir and submit the form to itself:
<?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>


#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 06 October 2006 - 10:53 AM

mkdir ( path, mode -> user right, permissions );

<?php

$base = 'test/';

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

mkdir ( $base . $dir, 0777 );

?>


me!

#5 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 06 October 2006 - 10:56 AM

Now just create a html form with a textfield called dir and submit the form to itself:

<?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>


Here what I get:
Warning: mkdir() expects parameter 2 to be long, string given in /users/3d_cn~1/html/gg/index.php on line 5
I don't need your script, I'll try to write it myself

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 10:57 AM

Here what I get:
Warning: mkdir() expects parameter 2 to be long, string given in /users/3d_cn~1/html/gg/index.php on line 5


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

<?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>

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 October 2006 - 10:59 AM

This:
mkdir("test/", $dir);

Is supposed to be:
mkdir("test/". $dir);


#8 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 06 October 2006 - 11:05 AM

And again:
Warning: mkdir(test/new_dir): No such file or directory in /users/3d_cn~1/html/test/index.php on line 5

yes Huggie, I've tryed your code to but the result is the same... Don't know what to do, thanks anyway guys!
I don't need your script, I'll try to write it myself

#9 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 06 October 2006 - 11:08 AM

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

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

Can I do something except changing this stupid server?
I don't need your script, I'll try to write it myself

#10 msknight

msknight
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 October 2006 - 11:12 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users