tom_d79 Posted May 8, 2007 Share Posted May 8, 2007 Hi, I have some html/css knowledge but php is essentially new to me.. I am trying to write (a simple I imagine) script that will allow a user to input a folder name and submit, the script then creating a folder in a location set in the script, set the permission to 0777 and then confirm that the folder was created.. I have spent the envening trying to do this but have got to the point where I really need some help and guidance from people who know what they are doing.. The code below is inserted into my page via an include.. needless to say it is not working. Would someone be kind enought to have a look at the code I have produced and point me in the right direction.. thanks <form action="" method="post"> Enter your folder name <input type="text" name="name" /> <input type="submit" /> </form> //does the dir already exist <?php $var = 'dir_exists'; $filename = '/guests/$name'; if (file_exists($filename)) { $dir_exists = '1' } else { $dir_exists = '0' } ?> //make dir <?php if (!isset($_POST['submit']) & $dir_exists=='0') { $name =$_POST['name']; mkdir("/guests/$name", 0777); echo "Your folder was created"; } else { echo "The foldername already exists"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50573-help-with-makdir-from-form/ Share on other sites More sharing options...
tom_d79 Posted May 9, 2007 Author Share Posted May 9, 2007 could anyone take a look at this for me? thanks Quote Link to comment https://forums.phpfreaks.com/topic/50573-help-with-makdir-from-form/#findComment-248783 Share on other sites More sharing options...
nikkieijpen Posted May 9, 2007 Share Posted May 9, 2007 What is the error you're getting? Take a look at this code: <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> Enter your folder name <input type="text" name="name" /> <input type="submit" /> </form> //does the dir already exist <?php $name =$_POST['name']; $filename = '/guests/$name'; if (!file_exists($filename) && !isset($_POST['submit'])) { // the ! means 'not'; The $_POST['submit'] has a value (or: is set) when the submit button is being clicked.... This means that when the button is clicked the directory will not be created. mkdir("/guests/$name", 0777); echo "Your folder was created"; } else { echo "The foldername already exists"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50573-help-with-makdir-from-form/#findComment-248811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.