forked from danmandle/JSON2CSV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json2csv.php
55 lines (46 loc) · 1.18 KB
/
json2csv.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
<?php
if((isset($_FILES["file"]["type"]) && $_FILES["file"]["type"] != NULL)
|| (isset($_POST['json']) && $_POST['json'] != NULL)
|| (isset($argv[1]))){
require_once('json2csv.class.php');
$JSON2CSV = new JSON2CSVutil;
if(isset($argv[1])){
$shortopts = "f::"; // Required value
$longopts = array("file::","dest::");
$arguments = getopt($shortopts, $longopts);
if(isset($arguments["dest"])){
$filepath = $arguments["dest"];
}
else{
$filepath = "JSON2.CSV";
}
$JSON2CSV->flattenjsonFile2csv($arguments["file"], $filepath);
}
elseif($_FILES["file"]["type"] != NULL){
$JSON2CSV->JSONfromFile($_FILES["file"]["tmp_name"]);
$JSON2CSV->flattenDL("JSON2.CSV");
}
elseif($_POST['json'] != NULL){
$JSON2CSV->readJSON($_POST['json']);
$JSON2CSV->flattenDL("JSON2.CSV");
}
}
else{
?>
<html>
<body>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data">
<label for="json">JSON data:</label>
<textarea name="json" cols="150" rows="40">
</textarea>
<br />
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Convert!" />
</form>
</body>
</html>
<?php
}
?>