public static function removeEmptyDirsToPath($dir, $path)
    {
        $dir = rtrim($dir, DIRECTORY_SEPARATOR);
        $path = rtrim($path, DIRECTORY_SEPARATOR);

        while ($dir != $path) {
            if (!static::removeDirIfEmpty($dir)) {
                break;
            }

            $dir = pathinfo($dir, PATHINFO_DIRNAME);
        }
    }
public static function removeEmptyDirsToPath($dir, $path)
    {
        $dir = rtrim($dir, DIRECTORY_SEPARATOR);
        $path = rtrim($path, DIRECTORY_SEPARATOR);

        while ($dir != $path) {
            if (!static::removeDirIfEmpty($dir)) {
                break;
            }

            $dir = pathinfo($dir, PATHINFO_DIRNAME);
        }
    }
public static function removeEmptyDirsToPath ( $ dir , $ path ) { $ dir = rtrim ( $ dir , DIRECTORY_SEPARATOR ) ; $ path = rtrim ( $ path , DIRECTORY_SEPARATOR ) ; while ( $ dir != $ path ) { if ( ! static :: removeDirIfEmpty ( $ dir ) ) { break ; } $ dir = pathinfo ( $ dir , PATHINFO_DIRNAME ) ; } }
Remove empty directory up to path

UtilFilesystem::removeEmptyDirsToPath(
pathinfo($file, PATHINFO_DIRNAME),
$this->getUploadRootDir()
);

from state :
.
`-- user
|-- d3
|   `-- 5d
`-- e8
`-- d9
`-- Clipboard02-kopiajfdksla-fds-afjdksla-fdsa-f-d-safdsa-f-d-sa-fd-s-af-d-sa-f-ds-a-fdusa-f-dsa-f-ds-a-fd-sa.bmpddd

removeEmptyDirsToPath('/var/docker/www/main/web/media/uploads/d3/5d', '/var/docker/www/main/web/media/uploads')

to state
.
`-- user
`-- e8
`-- d9
`-- Clipboard02-kopiajfdksla-fds-afjdksla-fdsa-f-d-safdsa-f-d-sa-fd-s-af-d-sa-f-ds-a-fdusa-f-dsa-f-ds-a-fd-sa.bmpddd



@param type $dir
@param type $path
Remove empty directory up to path