Created
August 22, 2013 17:58
-
-
Save dodopok/6310619 to your computer and use it in GitHub Desktop.
OH JUNAO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function admin_cadastrar() { | |
$this->set('title_for_layout', 'Novo Evento'); | |
if ($this->request->is('post')) { | |
$this->Evento->create(); | |
$destino = WWW_ROOT.'files/evento/fotos/'.$this->Evento->id.'/'; | |
$arquivo = $destino.$this->request->data['Evento']['fotos']['name']; | |
$ext = strtolower(end(explode('.',$arquivo))); | |
if($ext == 'zip'){ | |
$zip = new ZipArchive; | |
$res = $zip->open($arquivo); | |
$destinofotos = $destino.'zip/'; | |
mkdir($destinofotos); | |
$zip->extractTo($destinofotos); | |
$dh = opendir($destino); | |
// loop que busca todos os arquivos até que não encontre mais nada | |
$this->request->data['EventoFoto'] = array(); | |
while (false !== ($filename = readdir($dh))) { | |
if (is_file($destino.$filename)) { | |
$foto = $filename; | |
} | |
$this->request->data['EventoFoto'][] = array('nome' => $foto); | |
} | |
$zip->close(); | |
unlink($arquivo); | |
} | |
$this->Evento->saveAll($this->request->data); | |
$this->Session->setFlash('Eventos salvo com sucesso.'); | |
$this->redirect('/admin/eventos/gerenciar/'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment