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 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程