1
I’m trying to get my for
rotate according to how many pictures are 'inputadas' in SELECT. The problem is that regardless of how many images are 'inputadas', it only saves the first one. What’s wrong with this logic?
private function criarfoto($galeria_id, $file) {
$extension = "";
$valores = count($file['Foto']); // SALVA em quantidade,os indices que tem dentro do array.
for ($i = 0; $i < $valores; $i++) { // faz o loop de acordo com a quantidade de indices no array
$extension = pathinfo($file['Foto'][$i]['name'], PATHINFO_EXTENSION);
$allowExt = array('jpg', 'jpeg', 'png', 'gif');
//print_r($file);
if (!in_array($extension, $allowExt)) {
return false;
}
$fotos_galeria = array(
'galeria_id' => $galeria_id,
'titulo' => $file['titulo'],
'descricao' => $file['descricao'],
'extension' => $extension,
);
$this->Foto->create();
if ($this->Foto->save(array('Foto' => $fotos_galeria))) {
//die(print_r($fotos_galeria));
$foto_id = $this->Foto->id;
if (move_uploaded_file($file['Foto'][$i]['tmp_name'], WWW_ROOT . 'files' . DS . 'galeria' . DS . "{$foto_id}_o.{$extension}")) {
return $foto_id;
} else {
return false;
}
} else {
return false;
}
}
}
You can edit the question with the result of
var_dump($file)
within the functioncriarfoto()
? (to know what you’re input)– MoshMage