try catch try { $file_parts = pathinfo($dir); $t1 = $file_parts['extension']; if (strlen($t1)>0) { }else { mkdir($dir); } }catch(Exception $e){ }