File: /home/imensosw/public_html/imenso.co/matrix/admin/download_excel - Copy.php
<?php
error_reporting(0);
require_once '../config.php';
include('../PHPExcel/Classes/PHPExcel/IOFactory.php');
// require '../vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
$doc_no = $_POST['list'][0];
if(isset($doc_no))
{
$doc_no = explode(',', $doc_no);
$error = "";
$filePath = "../docs/";
if(extension_loaded('zip'))
{
if(isset($doc_no) && count($doc_no) == 1)
{
$file = $doc_no[0];
$objPHPExcel = new PHPExcel();
// $inputFileName ="../docs/$file/$file.xls";
$FileName = "../docs/$file/$file.xls" ;
if(file_exists($FileName))
{
$ext = 'xls';
}
else{
$ext = "xlsx";
}
$inputFileName = "../docs/$file/$file.".$ext ;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$objPHPExcel->setActiveSheetIndex(0);
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file.".$ext);
header("Cache-Control: max-age=0 ");
ob_clean();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
$objWriter->save('php://output');
}
else if(isset($doc_no) && count($doc_no)>1)
{
$zip = new ZipArchive();
$zip_name = date("Y-m-d").".zip";
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)
{
//$error.="Sorry zip creation failed.";
}
foreach($doc_no as $file)
{
$FileName = '$file/$file.xls';
if(file_exists($FileName))
{
$inputFileName = 'xls';
}
else{
$inputFileName = "xlsx";
}
$zip->addFile($filePath."$file/$file.".$inputFileName,"$file.".$inputFileName);
// $zip->addFile($filePath."$file/$file.xls","$file.xls");
// $zip->addFile($filePath."$file/$file.xls"); // Adding files into zip
}
$zip->close();
if(file_exists($zip_name))
{
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
// remove zip file is exists in temp path
unlink($zip_name);
}
else
{
//$error .= "File not exists ";
}
}
else
{
//$error .= "* Please select file to zip ";
}
}
/*$_SESSION['file_error'] = $error;
header("location:".$url."admin/assignment_completed.php");*/
}
?>