Get parent folder of current file PHP

php

Solution

The simpliest way is:

basename(__DIR__);

https://www.php.net/manual/en/language.constants.magic.php

Problem

I've done quite a bit of searching for this, so I'm sorry if this is a dupe. Anyway, I need to get the name of the folder the current file is in. For example, I want to convert something like `example.com/folder/subfolder/file.php` to `subfolder`. My current code is `dirname($_SERVER['PHP_SELF'])`, but that returns `/folder/subfolder` instead of `subfolder`. Thank you!

Original source