-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportafolio.php
80 lines (79 loc) · 3.35 KB
/
portafolio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php include("cabecera.php"); ?>
<?php include("conexion.php"); ?>
<?php
if($_POST){
print_r($_POST);
$nombre = $_POST['nombre'];
$descripcion = $_POST['descripcion'];
$fecha = new DateTime();
$imagen = $fecha->getTimestamp()."_".$_FILES['archivo']['name'];
$imagen_temporal = $_FILES['archivo']['tmp_name'];
move_uploaded_file($imagen_temporal, "imagenes/".$imagen);
$objConexion = new conexion();
$sql="INSERT INTO `proyectos` (`id`, `nombre`, `imagen`, `descripción`) VALUES (NULL, '$nombre', $imagen, 'Es un proyecto')";
$objConexion->ejecutar($sql);
header("location:portafolio.php");
}
if($_GET){
$id = $_GET['borrar'];
$objConexion = new conexion();
$imagen = $objConexion->consultar("SELECT imagen FROM `proyectos` WHERE id = ".$id);
unlink("imagenes/".$imagen[0]['imagen']);
$sql="DELETE FROM 'proyectos' WHERE 'proyectos'.'id'=".$id;
$objConexion->ejecutar($sql);
header("location:portafolio.php");
}
$objConexion = new conexion();
$proyectos = $objConexion->consultar("SELECT * FROM `proyectos`");
?>
<br/>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-header">
Datos del proyecto
</div>
<div class="card-body">
<form action="portafiolo.php" method="post" enctype="multipart/form-data">
Nombre del proyecto: <input require class="form-control" type="text" name="nombre" id="">
<br/>
Imagen del proyecto: <input require class="form-control" type="file" name="archivo" id=""> <br/>
<br/>
Descripción:
<textarea require class="form-control" name="descripcion" id="" rows="3"></textarea>
<br/>
<input class="btn btn-success" type="submit" value="Enviar proyecto">
</form>
</div>
<div class="card-footer text-muted">
</div>
</div>
</div>
<div class="col-md-6">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Imagen</th>
<th>Descripción</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php foreach($proyectos as $proyecto){ ?>
<tr>
<td><?php echo $proyecto['id']; ?></td>
<td><?php echo $proyecto['nombre']; ?></td>
<td><img width="100" src="imagenes/<?php echo $proyecto['imagen']; ?>" alt="" srcset="" ></td>
<td><?php echo $proyecto['descripción']; ?></td>
<th><a class="btn btn-danger" href="?borrar=<?php echo $proyecto['id']; ?>">Eliminar</a></th>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<?php include("pie.php"); ?>