R
R
Rafael Starkov2018-02-21 01:34:32
PHP
Rafael Starkov, 2018-02-21 01:34:32

How to check if a PHP directory exists?

Why is this code not working?

if (is_dir($_SERVER['DOCUMENT_ROOT'] . "/base/$keygen")) {
   echo "Эта папка существует";
} else {
   echo "Этой папки нет"; 
}

The php file itself is located in site.ru/api/index.php
And the checked folder is in site.ru/base/ HERE FOLDER

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-02-21
@namester

Goodnight.
The code is quite working.
Do I understand correctly that the api and base directories are on the same level?
What exactly doesn't work for you?
Check that the $keygen variable is empty.
Check what generally returns $_SERVER['DOCUMENT_ROOT'] . "/base/$keygen", maybe not the right way.
And in general, take a look at the server logs, maybe you have an error lying around somewhere and it is not displayed in the browser.

A
Alexey, 2018-02-21
@Azperin

As far as I remember, the document root returns with a slash, maybe it turns out double when cancatenating

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question