-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
executable file
·79 lines (70 loc) · 2.12 KB
/
upload.php
File metadata and controls
executable file
·79 lines (70 loc) · 2.12 KB
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Importar constancias para generar</title>
<style type="text/css">
body {
background: #E3F4FC;
color: #2b2b2b;
font-family: Helvetica, Arial, sans-serif;
}
a {
color:#898989;
font-size:14px;
font-weight:bold;
text-decoration:none;
}
a:hover {
color:#CC0033;
}
h1 {
text-align: center;
}
#container {
background: #CCC;
}
#form {padding: 10px;}
#form input {margin-bottom: 20px;}
</style>
</head>
<body>
<h1>Importar lista para generar constancias</h1>
<p>Formato: template_id, nombre de participante, email, evento[/sede]</p>
Ej:
<pre>
7 Fernando Hernández fernando@sg.com.mx sgvirtual
7 Pedro Galván Kondo pedrogk@gmail.com sgvirtual7/uabc
</pre>
<div id="container">
<div id="form">
<?php
require_once('constants.php');
$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h2>" . "Archivo ". $_FILES['filename']['name'] ." subido exitosamente." . "</h2>";
$handle = fopen($_FILES['filename']['tmp_name'], "r");
$import = "INSERT into constancias_generar (template_id, nombre_participante, email, tag) VALUES \n";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if(is_numeric($data[0])) {
$import .= "( $data[0],'$data[1]','$data[2]','$data[3]'),\n";
} // if
} // while
$import = chop($import, ",\n");
// print "<pre>$import</pre>"; // Si quieres debuggear el query string.
$db->exec($import);
print "<p>Insert exitoso</p>";
fclose($handle);
} // if
} else {
print "<form enctype='multipart/form-data' action='upload.php' method='post'>";
print "<p>Nombre del archivo a importar <br />";
print "<span style='font-size: 0.9em; font-style: italic;'>(usar archivo csv, separado por comas)</span>:</p>";
print "<input size='50' type='file' name='filename'><br />\n";
print "<input type='submit' name='submit' value='Upload'></form>";
}
?>
</div>
</div>
</body>
</html>