0

I already make a part of that function but when i do the check on my dir if they exist dont give any error, maybe u can help me found the miss part. Part of my function:

    public function teste_mkdir(){
        
                  
        $rootPath = '/var/www/oncargo/files/oncargophotos/';

        $data = '2022-11-25 23:59:45';
        $ano = date ('Y', strtotime($data));
        $mes = date ('m', strtotime($data));
        $dia = date ('d', strtotime($data));
        $path1 = $rootPath.$ano;
        $path2 = $path1.'/'.$mes;
        $path3 = $path2.'./'.$dia;
                    
//check if folders exists before create
        if(!is_dir($rootPath) == true){
            if(!is_dir($path1) == false)
                mkdir($path1,0777,true);
            if(!is_dir($path1) == true)
                if(!is_dir($path2) == false)
                    mkdir($path2,0777,true);
            if(!is_dir($path2) == true)
                if(!is_dir($path3) == false)
                    mkdir($path3,0777,true);
        }
//        print_r(array('ls' => scandir($path1))); make this to see if they are made but dont show nothing because they arent made
//        print_r(array('ls' => scandir($path2)));
//        print_r(array('ls' => scandir($path3)));
}

i alredy try make path1,2 andd 3, made i fail the rootPath is manual created. So im trying to get a new dir when data change, so every day when i receive a img that function have to create a dir for every single day. Its my purpose.Can u help me?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • What [debugging](https://www.atatus.com/blog/debugging-in-php/) have you done, to check the paths your code is taking? Do you understand what `!` does in a conditional expression? `if (!is_dir($rootPath) == true)` is actually saying "if rootPath _doesn't_ exist then...". And because you already created that root folder, it will never be true, and never enter the `if` block. I think you probably meant to write `if (is_dir($rootPath) == true)`. – ADyson Dec 13 '22 at 16:59
  • And `if(!is_dir($path1) == false)` should be `if(is_dir($path1) == false)`. You need to check the logic of all the others, too. – ADyson Dec 13 '22 at 17:00
  • See also https://stackoverflow.com/questions/13029921/exclamation-mark-in-front-of-variable-clarification-needed and https://www.php.net/manual/en/language.operators.logical.php – ADyson Dec 13 '22 at 17:00

0 Answers0