la base de datos se llama galeria, la tabla se llama productos, los campos que tienen la tabla son: id, titulo, imagen, descripcion, fecha
subir.view.php
Código HTML:
Ver original
<html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <link href="https://fonts.googleapis.com/css?family=Slabo+27px" rel="stylesheet"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous"> <link rel="stylesheet" href="css/estilos.css"> </head> <body> <header> <div class="contenedor"> </div> </header> <div class="contenedor"> <form class="formulario" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>"> <input type="file" id="foto" name="image"> <input type="text" id="titulo" name="title"> <?php if (isset($error)): ?> <?php endif ?> <input type="submit" class="submit" value="Guardar"> </form> </div> </body> </html>
funciones.php
Código PHP:
Ver original
<?php function conexion($db, $usuario, $pass){ try { $conexion = new PDO("mysql:host=localhost;dbname=$db", $usuario, $pass); return $conexion; } catch (PDOException $e) { return false; } } ?>
subir.php
Código PHP:
Ver original
<?php require 'funciones.php'; $conexion = conexion('galeria', 'root', ''); if (!$conexion) { } if ($check !== false) { $carpeta_destino = 'fotos/'; $archivo_subido = $carpeta_destino . $_FILES['image']['name']; $statement = $conexion->prepare(' INSERT INTO productos (id, titulo, imagen, descripcion) VALUES (:title, :image, :description) '); ':title' => $_POST['titulo'], ':image' => $_FILES['imagen']['name'], ':description' => $_POST['descripcion'] )); } else { $error = "El archivo no es una imagen o el archivo es muy pesado"; } } require 'views/subir.view.php'; ?>