Skip to content

Instantly share code, notes, and snippets.

@caferrari
Last active December 29, 2015 04:19
Show Gist options
  • Save caferrari/7613910 to your computer and use it in GitHub Desktop.
Save caferrari/7613910 to your computer and use it in GitHub Desktop.
ZF2 Upload Directory config
<?php
// module/Application/src/Application/Controller/FilesController.php
# ...
class FilesController
{
#...
public function indexAction()
{
$uploadDir = $this->getService('upload')->directory;
}
protected function getService($service)
{
return $this->getServiceLocator()->get($service);
}
#...
}
<?php
// module/Application/Module.php
#...
class Module
{
#...
public function getServiceConfig()
{
return array(
#...
'upload' => function ($sm) {
return (object)$sm->get('Config')['upload'];
}
#...
}
}
<?php
// config/autoload/upload.global.php
return array(
'upload' => array(
'directory' => '/pasta/dos/uploads/',
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment