【问题标题】:PhpExcel Library giving errorPhpExcel 库给出错误
【发布时间】:2016-01-24 10:44:46
【问题描述】:

我第一次尝试从 Excel 文件中读取数据,但遇到了一些问题。我正在使用 PhpExcel 库,我正在使用以下代码,现在 excel 文件已上传到文件夹中,但它没有显示 excel 文件的任何数据,并且它给出错误

“错误被捕获Could not open C:\xampp\tmp\phpF85B.tmp for reading!文件不存在。”

和类似的通知

注意:未定义变量:第 24 行 C:\xampp\htdocs\PhpExcel\index.php 中的 obj

注意:尝试在第 24 行获取 C:\xampp\htdocs\PhpExcel\index.php 中非对象的属性

最后

致命错误:在第 24 行对 C:\xampp\htdocs\PhpExcel\index.php 中的非对象调用成员函数 toArray()

<?php

if(isset($_POST['sub']) && !empty($_FILES['ex_file']['name'])){

$file=$_FILES['ex_file']['name'];
$type=explode(".",$file);
if(end($type)!= "xls" && end($type)!= "xlsx"){
    echo "The File is not and excel file";
    }

else{
    include "PhpExcelLib/Classes/PhpExcel/IOFactory.php";
    $dir="uploads/";
    $name=$_FILES['ex_file']['name'];
    $tmp_name=$_FILES['ex_file']['tmp_name'];
    if(move_uploaded_file($tmp_name,$dir.$name)){
        
        try{
            $obj=PhpExcel_IOFactory::load($tmp_name);
        }
        catch(Exception $e){
            echo "Error is catched". $e->getMessage();
        }
        $data=$obj->getActiveSheet->toArray(null,true,true,true);
        print_r($data);
    }
    else{
        echo "File is not uploaded";
    
}
}
}
?>
<html>
<body>
<form method="POST" enctype="multipart/form-data">
<label>Choose File To View Data</label>
<input type="file" name="ex_file" id="ex_file" />
<input type="submit" name="sub" value="Submit" />
</form>
</body>
</html>

【问题讨论】:

    标签: php phpexcel


    【解决方案1】:

    您的文件无法上传。

    检查一下,看看是什么导致了你的错误:

    // Check $_FILES['upfile']['error'] value.
    switch ($_FILES['upfile']['error']) {
        case UPLOAD_ERR_OK:
            break;
        case UPLOAD_ERR_NO_FILE:
            throw new RuntimeException('No file sent.');
        case UPLOAD_ERR_INI_SIZE:
        case UPLOAD_ERR_FORM_SIZE:
            throw new RuntimeException('Exceeded filesize limit.');
        default:
            throw new RuntimeException('Unknown errors.');
    }
    

    这应该让您了解错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多