hello I have a problem uploading an image to the server and saving the name in the database, upload the name of the image but do not save it on the server because when I see it, it says an object not found but if the name appears with the one that was kept in the BD, I can not understand what is happening I thought it was something related to the URL of the folders I was making changes but it was not successful, the structure is as follows:
addFactura.php
<?php require "controller/factura.php"; ?>
<div class="panel-body text-left">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="insertFactura" id="insertFactura" enctype="multipart/form-data">
<div class="form-group col-md-12">
<label for="imagen">Imagen de la Factura:</label>
<input id="imagen" class="form-control" type="file" value="" name="imagen" required="">
</div>
<div class="col-md-12">
<input type="hidden" name="grabar" value="si" />
</div>
<div class="col-md-8 col-md-offset-4 text-right">
<input type="submit" class="btn btn-success" value="Crear Factura" />
<a href="facturas.php" class="btn btn-danger">Cancelar</a>
</div>
</form>
</div>
</div>
</div>
controller / invoice.php
require 'lib/crud.php';
$mensaje = null;
$Factura = new Crud();
//Limpiamos los Inputs
#extenciones permitidas
$extencionPermitida = array('jpg', 'jpeg', 'gif', 'png', 'pdf');
#Carpeta donde se van a guardar las imagenes
$carpeta ='facturas/';
#recibimos el campo de la imagen
$imagen = $_FILES['imagen']['tmp_name'];
#Guardamos el nombre original de la imagen en una variable
$nombrebre_orig = $_FILES['imagen']['name'];
#Codigo para ver la imagen de la variable
$array_nombre = explode('.',$nombrebre_orig);
$cuenta_arr_nombre = count($array_nombre);
$extension = strtolower($array_nombre[--$cuenta_arr_nombre]);
#validar la extension
if(!in_array($extension, $extencionPermitida)) { $error = "Este tipo de archivo no es permitido";}
if(empty($error))
{
//creamos nuevo nombre para que tenga nombre unico
$nombre_nuevo = time().'_'.rand(0,100).'.'.$extension;
//nombre nuevo con la carpeta
$nombre_nuevo_con_carpeta = $carpeta.$nombre_nuevo;
//por fin movemos el archivo a la carpeta de imagenes
$mover_archivos = move_uploaded_file($imagen , $nombre_nuevo_con_carpeta);
//de damos permisos 777
chmod($nombre_nuevo_con_carpeta,0777);
}
lib / crud.php
public function upload()
{
$file = $this->file;
$tmp = $this->tmp;
#si existe el archivo
if(!empty($file))
{
$subir = $file;
#checamos si existe la Carpeta imagenes si no la creamos
if(!is_dir("facturas/"))
{
mkdir("facturas/", 0777);
}
#comprobacion de que se subio el archivo
if($subir && move_uploaded_file($tmp, "facturas/".$subir))
{
return true;
}
} return false;
}
ajax / verFactura.php
<?php
require_once('../lib/catalogo.php');
<div class="col-md-5">
<img src="facturas/<?php echo $imagen; ?>" class="img-responsive center-block img-thumbnail" alt="<?php echo $imagen; ?>"><br>
</div>
?>