1

I am trying to create a directory after a form submit, then after the form is submitted I want that directory to have a file stuffed inside of it. I have tried the php copy function and used an if statement to see if it was copying successfully but it is not. Please take a look at my code and see what is going on. And when it was working, it would just give a "1" output once submitted. No actual file was moved inside of the folder.

if($_POST['submit']=='Register') { // If the Register form has been submitted $root = "/serves/registered.php"; $err = array(); $folder = mkdir($_POST['username']); $reg = "registered.php"; mkdir($_POST['username']); copy($root,$folder); if (!copy($root, $folder)) { echo "failed to copy $root...\n"; } else { echo "Account was successfuly created."; } 

Thank you

3
  • Why on the earth do you do the copy twice? Commented Jan 24, 2016 at 13:41
  • To move files/folders you can use the rename function. But I don't understand what are you trying to do. Why do you mkdir($_POST['username']) and copy($root,$folder) twice? Commented Jan 24, 2016 at 13:43
  • @HtmHell right that is the username the user is creating, and in turn that will create a new directory with his username he has chosen. Now we want a file inside of that directory on the submit button has been clicked. Commented Jan 24, 2016 at 13:46

2 Answers 2

1

This can do it:

$root = "serves/registered.php"; $folder = mkdir($_POST['username']); if($folder) { $reg = "registered.php"; if (!copy($root, $_POST['username']."/".$reg)) { echo "failed to copy $root...\n"; } else { echo "Account was successfuly created."; } } else { echo "Could not create folder"; } 
Sign up to request clarification or add additional context in comments.

Comments

0
if($_POST['submit']=='Register') { // If the Register form has been submitted $root = "contact.php"; $folder = $_POST['username'] . '/' . $root; mkdir($_POST['username']); if (!copy($root, $folder)) { echo "failed to copy $root...\n"; } else { echo "Account was successfuly created."; } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.