Search code examples
phpmkdir

Creating a folder with username using PHP


I think this may sound very straight forward, but still something is not working out. I am trying to create a folder with the name which is posted by the user and create a folder in the same directory. But I am not able to create one.

Here is my code:

$Name = $_POST['name'];     

$thisdir = getcwd(); 

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

mkdir($folderPath);

chmod($folderPath, 0777);

What can be the problem, where am I making mistake or is the problem lying with server settings. If so what should be done to change the PHP server settings

Thanks


Solution

  • I suggest the following:

    1. Check that you are getting data from $_POST using 'name' as the key.

    2. Use '/' instead of '\' in the file path

    3. Check you have permissions to create the directory in the current working directory (YOU may have, but does the webserver?)