-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocesar.php
52 lines (34 loc) · 1.05 KB
/
procesar.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
<?php
include("conexion.php");
$cn = Conexion();
if (substr($_FILES['excel']['name'],-3)=="csv")
{
$fecha = date("Y-m-d");
$carpeta = "tmp_excel/";
$excel = $fecha."-".$_FILES['excel']['name'];
move_uploaded_file($_FILES['excel']['tmp_name'], "$carpeta$excel");
$row = 1;
$fp = fopen ("$carpeta$excel","r");
//fgetcsv. obtiene los valores que estan en el csv y los extrae.
while ($data = fgetcsv ($fp, 1000, ","))
{
//si la linea es igual a 1 no guardamos por que serian los titulos de la hoja del excel.
if ($row!=1)
{
$num = count($data);
$insertar="INSERT INTO agenda_datos (nombres,apellidos,direccion,celular,email)
VALUES ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
$sql = mysql_query($insertar) or die(mysql_error());
if (!$sql)
{
echo "<div>Hubo un problema al momento de importar porfavor vuelva a intentarlo</div >";
exit;
}
}
$row++;
}
fclose ($fp);
echo "<div>La importacion de archivo subio satisfactoriamente</div >";
exit;
}
?>