In my application, to move a file to a specific directory i need to know public folder path in controller action. I read different this type solution but not getting easy one. I know that in view we can get easily public folder path using $this->basePath();
view helper. I exactly want this in controller action. Anybody can guide me how can i achieve that. Thanks in advance.
index.php
sets the current working dir to you application root (the folder containing composer.json
, init_autoloader.php
, etc.)
As long as you haven't called chdir
elsewhere in your application you can call getcwd()
and it'll always return the path to your app root.
Since the public folder is relative to that, you can get the path using ...
$publicDir = getcwd() . '/public';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With