doumang20060820 2015-02-26 09:18
浏览 219
已采纳

phpExcel:无法加载资源:net :: ERR_CONNECTION_RESET

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);
        }
    }
}
?>
  • 写回答

1条回答 默认 最新

  • dongliang7545 2015-02-27 08:27
    关注

    I find the problem come from the library in the file PHPExcel/Calculation.php.

    You have to add a line at the begin of the class PHPExcel_Calculation add a line private $saveThis; and in the construct function(line 1722) add a line $this->saveThis = $this; and in the destruct function (line 1740) remplace $this by $saveThis

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的