I need a function, native or custom, that checks if a string is a valid directory name. I looked through the PHP documentation and I can only find a function is_dirthat checks if this existing directory exists or not, and not a valid name for the directory.
is_dir
This should work for you.
See regex for checking folder name and file name
if (strpbrk($filename, "\\/?%*:|\"<>") === FALSE) { /* $filename is legal; doesn't contain illegal character. */ } else { /* $filename contains at least one illegal character. */ }
It will work. You can change the second and third arguments to suit your needs.
if (!mkdir($directory, 0700, true)) { die('Error: Illegal directory.'); }
, , . , (, ), . , , , .
, , , .
, , .
, , mkdir() (, , , ..), . , PHP , , , , , , mkdir().
mkdir()