- $fh = fopen($targetTmp, 'r');
- header('Content-type: application/vnd.ms-excel');
+ if (!empty($_POST['format']) && $_POST['format']=='xlsx') {
+ require_once 'File/Convert.php';
+ $cc = new File_Convert($targetTmp,'application/vnd.ms-excel');
+ $targetTmp = $cc->convert('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+ if (empty($targetTmp)) {
+ $this->jerr("convert to xlsx failed");
+ }
+
+ $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
+ $ext = "xlsx";
+ }
+ if (empty($fname)) {
+ $fname = basename($targetTmp);
+ }
+ $fname .= preg_match('/\.' . $ext . '/i', $fname) ? '' : ('.' . $ext); // make sure it ends in xls..
+
+
+ DB_DataObject::factory('Events')->addFile(array(
+ 'tmp_name' => $targetTmp,
+ 'name' => $fname,
+ 'type' => $mime,
+ 'size' => filesize($targetTmp)
+ ));
+
+ $this->addEvent("DOWNLOAD", false, $fname );
+
+ // unlink($srcTmp);
+
+ header('Content-type: ' . $mime);