public function createAction()
{
if ($this->getRequest()->isPost()) {
$form = new Application_Form_Plik();
if ($form->isValid($this->getRequest()->getPost())) {
$dane = $form->getValues();
$np = realpath(APPLICATION_PATH . '/../public/uploads/' . $dane['slug']);
$contents = file_get_contents($np);
$path_parts = pathinfo($np);
unlink($np);
$dane['dane'] = $contents;
$dane['typmime'] = My_Mime::getMimetypeOnExt($path_parts['extension']);
$Plik = new Application_Model_DbTable_Plik();
$id = $Plik->createRow($dane)->save();
return $this->_helper->redirector('index');
}
$this->view->form = $form;
} else {
throw new Exception('Błędny adres!', 404);
}
}
Listing 31.8. Kod akcji create
Rozdział 31. Przesyłanie plików na serwer