Error creating directory with php same using file_exists

0

Personal beauty? I have a problem that is as follows. I use the following code to create a directory.

    //verifica se existe diretorio para criar
$dir = 'imagens/'.$id_produto.'/';

if(!file_exists($dir)){
  mkdir($dir, 0777);
}else{
  echo "Erro ao criar diretório";
}

But even going there in the folder and leaving it clean, running this code it points out that the directory exists. I have already displayed echo file_exists($dir); separately and it returns me 1 as if the directory existed. The strange thing is that it came to normal and now I have this problem. any ideas?

    
asked by anonymous 15.10.2018 / 16:25

2 answers

2

Try this

mkdir($dir, 0777, true);

    
15.10.2018 / 16:31
0

Try using the is_dir function see link

Remove the last concatenation in $dir , follow the example below.

$dir = 'imagens/'.$id_produto;
if(!is_dir($dir)){
   mkdir($dir, 0777,true);
    // verifica novamente
    if (!is_dir($dir)){
        echo "erro ao criar";
    } else{ 
        echo "dir criado agora ".time();
    }
}else{
    echo "dir existe";
}
    
16.10.2018 / 02:30