hola a todos, quería hacerles la sgte consulta, estoy usando MVC a mano y resulta que necesito trabajar con imagenes: en la página me da el sgte error:
Notice: Undefined index: foto in /var/www/html/amnesia_1/Controller/VehiculosController.php on line 44
el código en el VehiculoController es este:
public function add(){
if(Session::get("tipo") == "admin"){
Session::set('mod', isset($_POST['txtmod']) ? $_POST['txtmod'] : Session::get('mod'));
$modelos = (Session::get('mod')!="") ? $this->mod_v->obtenerXDataList(Session::get('mod')) : array();
$tiposveh= $this->mod_tv->obtenerTodos();
if (isset($_POST['btnaceptar'])) {
if(empty($_POST['txtmat']) or empty($_POST['txtcant']) or empty($_POST['txtmod'])){
Session::set("msg","Ingrese los datos obligatorios (*) para continuar.");
Session::set('modelos', $modelos);
Session::set('tiposveh', $tiposveh);
$this->redirect(array('add.php'));
}
else{
if($this->checkImage($_FILES['foto'])!= null){
}
else {
Session::set("msg","Hubo un fallo al subir la imagen");
Session::set('modelos', $modelos);
Session::set('tiposveh', $tiposveh);
$this->redirect(array('add.php'));
}
}
}
else {
Session::set('modelos', $modelos);
Session::set('tiposveh', $tiposveh);
$this->redirect(array('add.php'));
}
}
else {
Session::set("msg","Debe ser administrador para acceder.");
$this->redirect(array('Main','index.php'));
}
}
private function checkImage($file){
if ($file["error"] > 0){
// echo "ha ocurrido un error";
return null;
} else {
$permitidos = array("image/jpg", "image/jpeg", "image/gif", "image/png");
$nombre = $file['name'];
$limite_kb = 100;
if (in_array($file['type'], $permitidos) && $file['size'] <= $limite_kb * 1024){
$ruta = "View/Layout/upload" . $nombre;
if (!file_exists($ruta)){
$resultado = @move_uploaded_file($file["tmp_name"], $ruta);
return ($resultado) ? $nombre : null;
} /*else {
echo $nombre . ", este archivo existe";
}*/
} else {
//echo "archivo no permitido, es tipo de archivo prohibido o excede el tamano de $limite_kb Kilobytes";
return null;
}
}
}
y en la vista Vehiculos/add.php:
<h3>Crear Vehículo</h3>
<form method="post" action="index.php?c=vehiculos&a=add" name="frm_addveh">
<table>
<tr>
<td><label for="mat">Matrícula del Vehículo:</label></td>
<td><input type="text" name="txtmat" id="mat" autofocus required="required" placeholder="Ingrese Matrícula" /></td>
</tr>
<tr>
<td><label for="cant">Cantidad del Vehículo:</label></td>
<td><input type="text" name="txtcant" id="cant" required="required" placeholder="Ingrese Cantidad" /></td>
</tr>
<tr>
<td><label for="descrip">Descripción del Vehículo:</label></td>
<td><textarea id="descrip" name="txtdes" rows="10" cols="40"></textarea></td>
</tr>
<tr>
<td><label for="foto">Foto del Vehículo:</label></td>
<!-- esta es la parte de la imagen -->
<td><input type="file" name="foto" id="foto" required="required" /></td>
</tr>
<tr>
<td>Modelo del Vehículo:</td>
<td>
<input id="mod" list="modelos" required="required" name="txtmod" />
<datalist id="modelos">
<?php foreach (Session::get('modelos') as $modelo) { ?>
<option value=<?php echo $modelo['id'];?> ><?php echo $modelo['marca']." - ".$modelo['nom'];?> </option>
<?php }?>
</datalist>
<input type="button" onclick="frm_addveh.submit();" value="Buscar" />
</td>
</tr>
<tr>
<td><label for="tipo">Tipo del Vehículo:</label></td>
<td>
<select name="cboxtipo" id="tipo">
<?php foreach (Session::get('tiposveh') as $tipoveh) { ?>
<option value="<?php echo $tipoveh['id']; ?>"><?php echo $tipoveh['nom']; ?></option>
<?php }?>
</select>
</td>
</tr>
</table>
<p>
<input type="submit" value="Aceptar" name="btnaceptar" />
<a href="index.php?c=vehiculos&a=index"><input type="button" value="Cancelar" /></a>
</p>
</form>
Estuve buscando, probando pero no dí con la respuesta.
Espero sus respuestas y saludos.