Upload PHP

18:29Fresh Young´s

function cadastro(){

$this->layout = 'cadastro';

if(!empty($this->request->data)){
$max_files = 2;
$i = 0;
$data = $this->request->data['Empresa']['uploadfile'];
if(!empty($data)){
if(count($data)>$max_files){
throw new NotFoundException("Error Processing Request {$this->max_files}", 1);
}
foreach ($data AS $file) {
$filename=$file['name'];
$file_temp_name = $file['tmp_name'];
$dir = WWW_ROOT.'img';
$allwoed = array('png','jpg','jpeg','JPG');
if(!in_array(substr(strrchr($filename,'.'), 1),$allwoed)){

}elseif (is_uploaded_file($file_temp_name)) {

$nome = null;
$nomeasalvar = null;
$nomeasalvar = String::uuid().substr($filename, -4);

$nome = $dir.DS.$nomeasalvar;
$img[$i] = $nomeasalvar;
$i = $i +1;

$mover = move_uploaded_file($nomesalvar);




}
}
if (empty($img[0])) {$img[0] = '';}
$gravar = array('Empresa' => array(
'banner' => $img[0],
'nome' => $this->request->data['Empresa']['nome'],
'telefone1' => $this->request->data['Empresa']['telefone1'],
'telefone2' => $this->request->data['Empresa']['telefone2'],
'endereco' => $this->request->data['Empresa']['endereco'],
'bairro' => $this->request->data['Empresa']['bairro'],
'site' => $this->request->data['Empresa']['site'],
'facebook' => $this->request->data['Empresa']['facebook'],
'valorpago' => '',
'status' => 0,
'mapa' => '',
'estado' => $this->request->data['Empresa']['estado'],
'cidade' => $this->request->data['Empresa']['cidade'],
'categoria_id' => $this->request->data['Empresa']['categoria_id'],


));

$this->Empresa->save($gravar);


$this->redirect(array('action' => 'cadastro'));

}


}



}

You Might Also Like

0 comentários

Popular Posts

Formulário de Contacto