Skip to content

Instantly share code, notes, and snippets.

@dodopok
Created August 22, 2013 17:58
Show Gist options
  • Save dodopok/6310619 to your computer and use it in GitHub Desktop.
Save dodopok/6310619 to your computer and use it in GitHub Desktop.
OH JUNAO
<?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