ÿØÿà JFIF ÿÛ „ ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /var/www/html/thietkewebvumi.com/lib/sql2xls/ |
<?php require("db.inc.php"); require("excelwriter.inc.php"); Class HarImport { var $db=null; var $error=""; //String function HarImport() { } /* * @Params * $host : Host name of mysql database * $user : User * $pwd : Password * $databse : database name */ function openDatabase($host,$user,$pwd,$database) { $this->db=new DB(); $this->db->open($host,$user,$pwd,$database); if(!$this->db) { $this->error=$this->db->error(); return false; } } /* * @Params * $tnlName=Name of table from the data is imported to excel file * $fileName=Name of the file wants to save as.On leaving balnk it takes the table name as file name * $download=Boolean value whether you wants to save on disk or you want to force to download the file. */ function ImportDataFromTable($tblName,$fileName="",$download=false) { if(empty($fileName)) $fileName=$tblName.".xls"; $sql="SELECT * FROM $tblName"; return $this->ImportData($sql,$fileName,$download); } /* * @Params * $sql=A valid SQL query. * $fileName=Name of the file wants to save as.On leaving balnk it takes the table name as file name * $download=Boolean value whether you wants to save on disk or you want to force to download the file. */ function ImportData($sql,$fileName="har_excel.xls",$download=true) { $excel=new ExcelWriter($fileName); if($excel==false) { $this->error=$excel->error; return false; } $this->db->query($sql); if($this->db->numRows()==0) { $this->error="No data found in the table"; return false; } if($row=$this->db->fetchAssoc()) { for($i=0;$i<count($row);$i++) { $fields[]=$this->db->fieldName($i); } $excel->writeLine($fields); do { $excel->writeLine($row); }while($row=$this->db->fetchAssoc()); } $excel->close(); $this->db->close(); if($download) { if(!headers_sent()) $this->download_file($fileName,true); else { $this->error="Error :Headers already Sent.Can't Download file."; } } return; } function download_file($filename,$isDel=true) { $file=basename($filename); if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); } // make sure the file exists before sending headers if(!$fdl=@fopen($filename,'r')) { die("<br>Cannot Open File!<br>"); } else { header("Cache-Control: ");// leave blank to avoid IE errors header("Pragma: ");// leave blank to avoid IE errors header("Content-type: application/octet-stream; charset=utf-8"); header("Content-Disposition: attachment; filename=\"$file\""); header("Content-length:".(string)(filesize($filename))); sleep(1); fpassthru($fdl); } if($isDel) { @unlink($filename); } } } ?>