-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcsvimport.php
69 lines (57 loc) · 1.62 KB
/
csvimport.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
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @return array
* @link http://gist.github.com/385876
* @author Jay Williams <http://myd3.com/>
* @copyright Copyright (c) 2010, Jay Williams
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
function csv_to_array($filename='', $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename))
return FALSE;
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
if (!$_FILES["file"]["error"] > 0 && $_FILES["file"]["type"] == 'text/csv') {
$devices = csv_to_array($_FILES["file"]["tmp_name"]);
if (isset($devices)) {
include('ardgen.php');
}
} else {
echo '<html>
<body>
<h1>CSV to ARD Import List</h1>
<p>Download an example/template CSV <a href="examplecsv.zip">here</a>.
<ul>
<li>Only the name and networkAddress (IP address) are required fields, hardwareAddress (MAC address) is optional.</li>
</ul>
<p>Please select a CSV file you wish to convert.</p>
<form action="" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Convert">
</form>
</body>
</html>';
}
?>