-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathguarda.php
58 lines (45 loc) · 1.56 KB
/
guarda.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
<?php
/**
* CRUD modal en PHP y MySQL
*
* Este archivo guarda los datos el registro y la imagen
* @author MRoblesDev
* @version 1.0
* https://github.com/mroblesdev
*
*/
session_start();
require 'config/database.php';
$nombre = $conn->real_escape_string($_POST['nombre']);
$descripcion = $conn->real_escape_string($_POST['descripcion']);
$genero = $conn->real_escape_string($_POST['genero']);
$sql = "INSERT INTO pelicula (nombre, descripcion, id_genero, fecha_alta)
VALUES ('$nombre', '$descripcion', $genero, NOW())";
if ($conn->query($sql)) {
$id = $conn->insert_id;
$_SESSION['color'] = "success";
$_SESSION['msg'] = "Registro guardado";
if ($_FILES['poster']['error'] == UPLOAD_ERR_OK) {
$permitidos = array("image/jpg", "image/jpeg");
if (in_array($_FILES['poster']['type'], $permitidos)) {
$dir = "posters";
$info_img = pathinfo($_FILES['poster']['name']);
$info_img['extension'];
$poster = $dir . '/' . $id . '.jpg';
if (!file_exists($dir)) {
mkdir($dir, 0777);
}
if (!move_uploaded_file($_FILES['poster']['tmp_name'], $poster)) {
$_SESSION['color'] = "danger";
$_SESSION['msg'] .= "<br>Error al guardar imagen";
}
} else {
$_SESSION['color'] = "danger";
$_SESSION['msg'] .= "<br>Formato de imágen no permitido";
}
}
} else {
$_SESSION['color'] = "danger";
$_SESSION['msg'] = "Error al guarda imágen";
}
header('Location: index.php');