Skip to content

Commit ac173ec

Browse files
Create csv2html.php
1 parent 626ffb6 commit ac173ec

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

csv2html.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
if(!empty(isset($_POST["upload"]))) {
3+
if (($fp = fopen($_FILES["file-input"]["tmp_name"], "r")) !== FALSE) {
4+
?>
5+
<table class="tutorial-table" width="100%" border="1" cellspacing="0">
6+
<?php
7+
$i = 0;
8+
while (($row = fgetcsv($fp)) !== false) {
9+
$class ="";
10+
if($i==0) {
11+
$class = "header";
12+
}
13+
?>
14+
<tr>
15+
<td class="<?php echo $class; ?>"><?php echo $row[0]; ?></td>
16+
<td class="<?php echo $class; ?>"><?php echo $row[1]; ?></td>
17+
<td class="<?php echo $class; ?>"><?php echo $row[2]; ?></td>
18+
</tr>
19+
<?php
20+
$i ++;
21+
}
22+
fclose($fp);
23+
?>
24+
</table>
25+
<?php
26+
$response = array("type" => "success", "message" => "CSV is converted to HTML successfully");
27+
} else {
28+
$response = array("type" => "error", "message" => "Unable to process CSV");
29+
}
30+
}
31+
?>
32+
</div>
33+
<?php if(!empty($response)) { ?>
34+
<div class="response <?php echo $response["type"]; ?>
35+
">
36+
<?php echo $response["message"]; ?>
37+
</div>
38+
<?php } ?>

0 commit comments

Comments
 (0)