forked from shawnbot/csv2json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.php
94 lines (84 loc) · 3.47 KB
/
form.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
<?php
/*
* vim:et sts=2 sw=2 ai nocindent:
* by Shawn Allen, shawn at stamen dot com
*
* NOTE: This file is not intended to work standalone, but is included by
* index.php.
*/
?>
<html>
<head>
<title>CSV → JSON</title>
<style type="text/css">@import url(style.css);</style>
</head>
<body>
<h1>CSV → JSON</h1>
<form id="input" action="<?= $_SERVER['REQUEST_URI'] ?>"
method="POST" enctype="multipart/form-data">
<?php if (isset($max_form_size)): ?>
<input type="hidden" name="MAX_FILE_SIZE" value="<?= $max_form_size ?>"/>
<?php endif; ?>
<h2>CSV Input</h2>
<ol>
<li id="upload">
<label>Upload a file (max size: <strong><?= $max_upload_size ?></strong>):
<input type="file" name="upload" /></label>
<em class="either-or">or</em>
</li>
<li id="post">
<p><label for="csv">Paste your data here:</label></p>
<textarea name="csv" cols="50" rows="5"><?= $input ?></textarea>
</li>
</ol>
<h3>Input Options</h3>
<ul>
<li><label>Columns separated by:
<select name="delimiter_select" onchange="
if (this.selectedIndex < this.options.length - 1) {
document.getElementById('delimiter').value = this.options[this.selectedIndex].value;
}
">
<option value=",">,</option>
<option value=";">;</option>
<option value="tab">tab</option>
<option value="|">|</option>
<option value="" selected="selected">other:</option>
</select>
<input id="delimiter" name="delimiter" type="text" size="1" value="<?= escape($delimiter) ?>"/></label></li>
<li><label>Columns quoted with:
<input name="quotechar" type="text" size="1" value="<?= escape($quotechar) ?>"/></label></li>
</ul>
<h3>Output Options</h3>
<ul>
<li><label>JSON-P callback function:
<input name="callback" type="text" size="16" value="<?= escape($callback) ?>"/></label>
<em class="either-or">or</em>
</li>
<li><label>Assign to JavaScript variable name:
<input name="variable" type="text" size="16" value="<?= escape($variable) ?>"/></label></li>
<li><label>Indent JSON by
<input name="indent" type="text" size="1" value="<?= escape($indent) ?>"/> spaces</label></li>
<li><label><input type="checkbox" name="download" value="true" <?php if ($download) print 'checked="checked"'; ?> />
Download as file (rather than displaying in a text field).</label>
<div>File name: <input name="download_name" type="text" size="16" value="<?= escape($output_filename) ?>" /></div></li>
</ul>
<p class="submit"><input type="submit" text="Submit"/> <input type="reset" value="Reset"/></p>
</form>
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST'): ?>
<form id="output">
<h2>JSON Output</h2>
<?php if (!empty($error)): ?>
<p class="error"><strong><?= $error ?></strong></p>
<?php endif; ?>
<?php if (!empty($cmd)): ?>
<pre id="cmd">$ <?= $cmd ?></pre>
<?php endif; ?>
<?php if (!empty($json)): ?>
<p class="patience"><em>Be patient. Writing <?= pretty_size(mb_strlen($json)) ?> of JSON...</em></p>
<textarea id="output" cols="50" rows="32"><?= escape(trim($json), false) ?></textarea>
<?php endif; ?>
</form>
<?php endif; ?>
</body>
</html>