-1

I can't quite figure out how to add files from a sample directory that I have. I would appreciate some help. I have successfully created a new directory when ever a user inputs their username, but the contents are empty.

Edit: I've created the desired directory structure, just need to include/copy over the pages that I have in the sample template.

<?php
     $fileName = "/associate/sample/";

    $Name = $_POST['name'];

    $thisdir = getcwd();

    $folderPath = $thisdir . '/' . $Name;

    mkdir($folderPath);

    chmod($folderPath, 0777);

    file_put_contents (realpath("$fileName"), associate/$Name);

    ?>
Joshua Adams
  • 39
  • 1
  • 8
  • You've got a bunch of weird things going on here... What directory structure are you trying to create? What file name are you trying to create? and what are you trying to write to the file? – ElefantPhace Sep 03 '15 at 03:29
  • I have a membership site. Whenever a user inputs their username it creates a new folder with their username (associate/username). I've created a template with multiple pages that I want to include inside the newly developed folder. I apologize if this sounds like gibberish. – Joshua Adams Sep 03 '15 at 03:33

1 Answers1

2

You were close, just not quite doing it right. Look this over, and compare with what you have to see what I've done differently

$folder = "/associate/";
$name = 'Joshua';
$thisdir = getcwd();
$folderPath = $thisdir . $folder . $name;
$filename  = $name.'.file';
if(!file_exists($folderPath)){
  mkdir($folderPath);
  chmod($folderPath,0777);
}
$textToWrite = 'this is some text';
file_put_contents(realpath($folderPath).'/'.$filename, $textToWrite);
ElefantPhace
  • 3,806
  • 3
  • 20
  • 36
  • Doesn't this remove the directory created by the user input from the form that was submitted? For instance, I had it create a new folder with the associate/username – Joshua Adams Sep 03 '15 at 03:53
  • 1
    just replace `'Joshua'` with your `$_POST` variable. But no this does not delete anything... – ElefantPhace Sep 03 '15 at 03:57