Greetings! I'm trying to upload an image from any pc directory, I've never tried this because I'm very lost, I hope you can help me! Thanks in advance. I'm going to skip code because there are several files. I have the form in "addProduct.php", it has already added enctype="multipart / form-data", the main code is this:
if(isset($_POST["iniciar"])){
$conexion = new conexion();
$foto = $_POST["foto"]; <----Linea 21
if($conexion->insertarProducto($foto))
{
header("Location: productos.php");
}
else
{
echo "No se ingreso correctamente el producto.";
}
}
Inside the form in html is the one in the image:
<input type="file" tabindex="4" accept="image/png, .jpeg, .jpg" class="form-control" id="foto" name = "foto" placeholder="Nombre del producto" maxlength="100" required>
Finally it is sent to conexion.class.php, the code that I have there is this:
public function insertarProducto($foto)
{
$nombre_img = $_FILES['foto']['name'];
$directorio = $_SERVER['DOCUMENT_ROOT'].'/Practica/imagenes/';
move_uploaded_file($_FILES['foto']['tmp_name'],$directorio.$nombre_img);
$consulta = "Call InsertarProducto('".$foto."')";
if($this->conn->query($consulta)===true)
{
return true;
}
else
return false;
}
I think I do not have anything left! When sending the data I get this error: Notice: Undefined index: photo in C: \ Users \ xxxxxx \ Desktop \ xampp \ htdocs \ Practice \ addProducts.php on line 21