Gruzin Posted October 6, 2006 Share Posted October 6, 2006 hi guys,I need to creat a directory, I've started from php.net:[code]<?php$dir = $_POST['dir']; // directory name from formmkdir("test/", $dir);?> [/code] Hope someone will help, thanks in advance,George Link to comment https://forums.phpfreaks.com/topic/23167-creat-directory/ Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 Try this:[code]<?php$dir = $_POST['dir']; // directory name from formmkdir("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).RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104903 Share on other sites More sharing options...
wildteen88 Posted October 6, 2006 Share Posted October 6, 2006 Now just create a html form with a textfield called dir and submit the form to itself:[code]<?phpif(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 More sharing options...
printf Posted October 6, 2006 Share Posted October 6, 2006 mkdir ( path, mode -> user right, permissions );[code]<?php$base = 'test/';$dir = $_POST['dir']; // make sure you validate thismkdir ( $base . $dir, 0777 );?>[/code]me! Link to comment https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104906 Share on other sites More sharing options...
Gruzin Posted October 6, 2006 Author Share Posted October 6, 2006 [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]<?phpif(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 More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 [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]<?phpif(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 More sharing options...
wildteen88 Posted October 6, 2006 Share Posted October 6, 2006 This:[code=php:0]mkdir("test/", $dir);[/code]Is supposed to be:[code=php:0]mkdir("test/". $dir);[/code] Link to comment https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104911 Share on other sites More sharing options...
Gruzin Posted October 6, 2006 Author Share Posted October 6, 2006 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! Link to comment https://forums.phpfreaks.com/topic/23167-creat-directory/#findComment-104919 Share on other sites More sharing options...
Gruzin Posted October 6, 2006 Author Share Posted October 6, 2006 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 More sharing options...
msknight Posted October 6, 2006 Share Posted October 6, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.