-
Notifications
You must be signed in to change notification settings - Fork 0
/
cargarAutor.php
202 lines (178 loc) · 5.08 KB
/
cargarAutor.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
/**
* @author iberlot
* @version 20151223
* @package Mytthos
* @category General
*
* Encargado de cargar los datos de los autores
*
*/
require_once ("Config/includes.php");
echo "<table>\n";
$directorio = "Biblioteca";
$archivo = scandir ($directorio);
?>
<html>
<HEAD>
<TITLE>Carga de Autore</TITLE>
</HEAD>
<BODY>
<div id='content'>
<div id="separadorh"></div>
<legend>
<h3>Carga de Autores</h3>
</legend>
<div id="separadorh"></div>
<div id='cuerpo' align='center'>
<fieldset>
<form method="POST" action="#" enctype="multipart/form-data">
Apellido: <br> <input type="text" name="apellido"> <br> <br> Nombre: <br> <input type="text" name="realname"> <br> <br> Segundo Nombre: <br> <input type="text" name="segname"> <br> <br> Fecha de Nacimiento: <br> <input type="date" name="nac"> <br> <br> Fecha de Defuncion: <br> <input type="date" name="def"> <br> <br> Nacionalidad: <br>
<div class="ui-widget">
<select name='nacion' id='nacion'>
<?php
$sqlNacionalidad = "SELECT * FROM gentilicios";
echo $sqlNacionalidad;
$result = mysqli_query ($link, $sqlNacionalidad) or die ('Query error: ' . mysqli_error ($link));
while ($row2 = mysqli_fetch_array ($result, MYSQLI_ASSOC))
{
$combobit2 = ' <option value=' . $row2 ['idGentilicio'] . '>' . substr ($row2 ['nombreGentilicio'], 0, 50) . ' (' . substr ($row2 ['Pais'], 0, 50) . ') </option>'; // concatenamos el los options para luego ser insertado en el HTML
echo $combobit2;
}
?>
</select>
</div>
<br> <br> Notas: <br>
<textarea name="notas" rows="10" cols="40">Notas</textarea>
<br> <br> Imagen: <br> <input type=file name="file1"><br> <br> <input type='hidden' name='darDeAlta' value='1'> <input type="Submit" value="Dar de Alta">
</form>
</fieldset>
</div>
</div>
</BODY>
</html>
<script>
$(document).ready(function() { $("#nacion").select2(); });
</script>
<?php
/**
* inciamos el prosesamiento de datos en caso de que reciva el parametro "darDeAlta" en 1
*/
if ((isset ($_REQUEST ['darDeAlta'])) and ($_REQUEST ['darDeAlta'] == 1))
{
if (isset ($_REQUEST ['apellido']))
{
$apellido = trim ($_REQUEST ['apellido']);
}
if (isset ($_REQUEST ['realname']))
{
$realname = trim ($_REQUEST ['realname']);
}
if (isset ($_REQUEST ['segname']))
{
$segname = trim ($_REQUEST ['segname']);
}
if (isset ($_REQUEST ['nac']))
{
$nac = trim ($_REQUEST ['nac']);
}
if (isset ($_REQUEST ['def']))
{
$def = trim ($_REQUEST ['def']);
}
if (isset ($_REQUEST ['nacion']))
{
$nacion = trim ($_REQUEST ['nacion']);
}
if (isset ($_REQUEST ['notas']))
{
$Notas = trim ($_REQUEST ['notas']);
$Notas = htmlentities($Notas);
}
if (isset ($_FILES ['file1']) and $_FILES ['file1'] ['size'] > 1)
{
$nombre_tmp = $_FILES ['file1'] ['tmp_name'];
$nombreArch = $_FILES ['file1'] ['name'];
$tipo = $_FILES ['file1'] ['type'];
$tamano = $_FILES ['file1'] ['size'];
$ext_permitidas = array (
'pjpeg|jpeg|gif|png'
);
$partes_nombre = explode ('.', $nombreArch);
$extension = end ($partes_nombre);
$ext_correcta = in_array ($extension, $ext_permitidas);
$tipo_correcto = preg_match ('/^image\/(pjpeg|jpeg|gif|png|txt|doc|pdf|xls|sql|html|htm|php|sql)$/', $tipo);
$limite = 50000 * 1024;
if ($tamano <= $limite)
{
if ($_FILES ['file1'] ['error'] > 0)
{
echo 'Error: ' . $_FILES ['file1'] ['error'] . '<br/>' . var_dump ($_FILES) . " en linea " . __LINE__;
}
else
{
if (file_exists ($nombreArch))
{
echo '<br/>El archivo ya existe: ' . $nombreArch;
}
else
{
$estructura = "fotosAutores";
if (file_exists ($estructura))
{
move_uploaded_file ($nombre_tmp, $estructura . "/" . $nombreArch) or die (" Error en move_uploaded_file " . var_dump (move_uploaded_file) . " en linea " . __LINE__);
chmod ($estructura . "/" . $nombreArch, 0775);
}
else
{
mkdir ($estructura, 0777, true);
move_uploaded_file ($nombre_tmp, $estructura . "/" . $nombreArch) or die (" Error en move_uploaded_file " . var_dump (move_uploaded_file) . " en linea " . __LINE__);
chmod ($estructura . "/" . $nombreArch, 0775);
}
}
}
}
else
{
echo 'Archivo inválido';
}
}
if ($segname != "")
{
$tituloCarpeta = $apellido . "_" . $realname . "_" . $segname;
}
else
{
$tituloCarpeta = $apellido . "_" . $realname;
}
$sqlInsertAutor = "INSERT INTO Autor(
apellido,
nombre,
segNombre,
fechaNac,
fechaDec,
nacionalidad,
notas,
foto)
VALUES (
'$apellido',
'$realname',
'$segname',
'$nac',
'$def',
'$nacion',
'$Notas',
'$nombre'
)";
$result = mysqli_query ($link, $sqlInsertAutor) or die ('Query error: ' . mysqli_error ($link));
if ($result)
{
mkdir ("Biblioteca/" . $tituloCarpeta, 0775, true);
?>
<div id="dialog" title="Correcto" style='display: none;'>
<p>Datos Guardados!!!</p>
</div>
<?php
}
}
?>