The question is as follows:
How can I get the server path to the web directory in Symfony2 from inside the controller (or from anywhere else for that reason)
What I've already found (also, by searching here):
This is advised in the cookbook article on Doctrine file handling
$path = __DIR__ . '/../../../../web';
$path = $this->get('kernel')->getRootDir() . '/../web';
There's actually no direct way to get path to webdir in Symfony2 as the framework is completely independent of the webdir.
You can use
getRootDir() on instance of kernel class, just as you write. If you consider renaming
/web dir in future, you should make it configurable. For example AsseticBundle has such an option in its DI configuration (see here and here).