Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend 2:: getting public folder path or basePath() easily in controller action

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.

like image 975
karim_fci Avatar asked May 18 '14 10:05

karim_fci


1 Answers

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';
like image 57
Crisp Avatar answered Nov 15 '22 06:11

Crisp