Doubt mkdir operation

0

In this code to upload an image, how does mkdir work? I see in the php documentation that mkdir creates a directory but in the case that I show the directory is already created . This example works perfectly, I just want to know how it works mkdir do you create the folder or just choose the specified folder?

$id_banner=intval($_POST['id']);

$target_dir = "../../img/banner/";

$carpeta=$target_dir;

if (!file_exists($carpeta)) {
    mkdir($carpeta, 0777, true);
}
    
asked by RicardoKra 07.11.2018 в 12:24
source

2 answers

0

mkdir As you already know, it only works to create a new directory in the path you specify, now in the code you indicate if the directory already exists with the file_exists , with this function it verifies whether or not there is a file or directory returning as a result a boolean (true / false or 0/1), if it is false, you send it to create the dir with the permido of 777 .

    
answered by 07.11.2018 в 14:26
0

mkdir (Make Directory) creates a folder and returns true / false depending on whether the operation is successful. According to the PHP documentation .

  

bool mkdir (string $ directory [ int $ permissions = 0777 [ bool $ recursive =   false [ resource $ context]]])

$ directory: Name of the folder

$ permissions: Folder permissions (not applicable on windows systems)

$ recursive: If you have several nested folders that do not exist, create one by one.

$ context: I / O flow.

    
answered by 07.11.2018 в 15:17