Jump to content

Recommended Posts

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";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/50573-help-with-makdir-from-form/
Share on other sites

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";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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