How to create a folder for each user in PHP?

1

I would like an example of how to create a folder to store the data of each user in php, for example www.facebook.com/nomedeusuario

I imagine that in the sequence is saved an index within this folder and this index is created at the time of registration, with user information such as Facebook. Could someone give me an example of how to do this?

    
asked by anonymous 20.04.2016 / 12:43

1 answer

6

If you want to create folder, you will have to define a path or a directory where the folders will be created and save in a constant or variable and then take the name of the person and to create the folder, before any action check that the folder already exists. Here's an example below:

$pathName = "C:\php\www\pastas_user\" . $nome_user;

if(!file_exists($pathName )){
   mkdir($pathName); //aqui ele irá criar a pasta
} else {
   $pathName .= time(); //concatena a pasta para gerar com um nome diferente
   mkdir($pathName); //aqui ele irá criar a pasta
}

After that, just save the folder directory to the database in the user registry.

    
20.04.2016 / 16:06