Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
- echo "<link rel='stylesheet' href='..\styles.css'>";
- require('library/php-excel-reader/excel_reader2.php');
- require('library/SpreadsheetReader.php');
- require('db_config.php');
- if(isset($_POST['Submit'])){
- $mimes = ['application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
- if(in_array($_FILES["file"]["type"],$mimes)){
- $uploadFilePath = 'uploads/'.basename($_FILES['file']['name']);
- move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath);
- $Reader = new SpreadsheetReader($uploadFilePath);
- $totalSheet = count($Reader->sheets());
- echo "You have total ".$totalSheet." sheets<br><br>".
- $html="<table border='2px solid black'>";
- $html.="<tr><th>Description</th><th>Date</th><th>Amount</th><th>Merchant</th><th>Type</th><th>Source</th></tr>";
- $query = "Insert Into main(Description,Date,Amount,Merchant,Type, Source) Values(?, ?, ?, ?, ?, ?)";
- $stmp = $mysqli->prepare($query);
- /* For Loop for all sheets */
- for($i=0;$i<$totalSheet;$i++){
- $Reader->ChangeSheet($i);
- foreach ($Reader as $Row)
- {
- $html.="<tr>";
- $des = isset($Row[0]) ? $Row[0] : '';
- $d = isset($Row[1]) ? $Row[1] : '';
- $timestamp = DateTime::createFromFormat('d/m/Y',$d);
- $d1 = $timestamp->format('Y-m-d');
- $a = isset($Row[2]) ? $Row[2] : '';
- $m = isset($Row[3]) ? $Row[3] : '';
- $t = isset($Row[4]) ? $Row[4] : '';
- $s = isset($Row[5]) ? $Row[5] : '';
- if($des == '' || $d == '' || $a == '' || $m == '' || $s == '' || $t == ''){continue;}
- else{
- $html.="<td>".$des."</td>";
- $html.="<td>".$d1."</td>";
- $html.="<td>".$a."</td>";
- $html.="<td>".$m."</td>";
- $html.="<td>".$t."</td>";
- $html.="<td>".$s."</td>";
- $html.="</tr>";
- $stmp->bind_param('sissss', $des, $d1, $a, $m, $t, $s);
- $stmp->execute();
- }
- }
- $html.="</table>";
- echo $html;
- if(mysqli_error($mysqli) == ''){
- echo "<br />Data Inserted in dababase";}
- else{echo "Error: ";
- echo mysqli_error($mysqli);
- }};}
- else {die("<br/>Sorry, Your File type is not allowed. You can only use a <code>.xlsx</code> file or a <code>.xls</code> file.");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement