Does folder exist in PHP CodeIgniter

I want to create a simple search if a “folder” exists. If it doesn’t I want a notification similar to form_validation error.

I’ve developed the coding below however the 1st line works but the 2nd line doesn’t work.

$this->form_error('$boss', 'The boss username does not exist');

I want an error notification - The boss username does not exist’

But if the folder does exist then the process continues.

I’ve searched many sites which some come close but not precisely what I want.

Maybe the 2nd line can be replaced with some Javascript?

Can anybody guide me?

Update 10/09/2019

I get some sense out of the following;

if(!file_exists("C:xampp/htdocs/file1/name.php")) exit ("$name DoesNotExist");
if(!file_exists("C:xampp/htdocs/file2/name.php")) exit ("$name DoesNotExist");

It only works “sometimes” but I want it working “all the time”.

Is there some Javascript that can do the same job but without exiting?

Update 11/09/2019

As a result of searching for a remedy to this problem, I have found that it is inadvisable to facilitate client side programming (which is what Javascript is) to “file_exists” and “is_dir” functions due to security risks.

Therefore this matter should be CLOSED.