I actualy use phpExcel to get an excel file that i recover from the user with an <input type='file'>
and after i convert this excel file in csv file.
My script work and the csv file is generate. The problem is after my script finish the page never stop to loading and i get this error in my console : Failed to load resource: net::ERR_CONNECTION_RESET
.
Their is another problem i use also an other object in my script for display the menu and the menu don't display is i use PHPExcel.
Their is my code for call my PHPExcel object creation :
<?php
///Get excelFile ///
if(isset($_FILES['excelFileCandidat']))
{
require_once dirname(__FILE__) . "/../../lib/ExcelCandidat/ExcelCandidat.class.php";
$file = new ExcelCandidat($_FILES['excelFileCandidat']);
$file->excelFileToCsv();
}
echo "<table width='100%'>";
echo "<tr>";
echo "<td>";
echo "Import new Excel File : ";
echo "<input type='file' name='excelFileCandidat' />";
echo "</td>";
echo "<td>";
echo "<input type='submit' name='submit' value='Send' />";
echo "</td>";
echo "</tr>";
echo "</table>";
?>
And my object :
<?php
require_once dirname(__FILE__) . "/../PHPExcel/PHPExcel.php";
class ExcelCandidat
{
private $excelFile;
public function __construct($file)
{
$this->excelFile = $file;
}
public function excelFileToCsv()
{
set_time_limit(600);
if (!is_array($this->excelFile))
{
throw new Exception("STR_APPROCHECK_ERR");
}
$newFilename = 'csvCandidat';
$ext = strrchr($this->excelFile['name'], '.');
$isExcel = stripos($ext, '.xls') !== false;
if($isExcel)
{
ini_set('memory_limit', '256M');
$objPHPExcel = PHPExcel_IOFactory::load($this->excelFile['tmp_name']);
$worksheet = $objPHPExcel->getActiveSheet();
$writer = PHPExcel_IOFactory::createWriter($objPHPExcel , 'CSV');
$writer->setDelimiter(';');
$writer->setEnclosure('"');
$writer->setUseBOM(false);
$tmpName = dirname(__FILE__) . '/file/' . $newFilename . date('ymdHis') .'.csv';
$writer->save($tmpName);
unset($objPHPExcel, $writer);
}
}
}
?>