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 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?