Jump to content

help with makdir from form


tom_d79

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

Archived

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

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