我第一次尝试从 excel 文件中读取,但我遇到了一些问题。我正在使用PhpExcel库,我正在使用以下代码,现在excel文件已上传到文件夹中,但它没有显示excel文件的任何数据,并且给出错误
"捕获错误无法打开 C:''xampp''tmp''phpF85B.tmp 进行读取!文件不存在。
和通知,如
注意:未定义的变量:obj in C:''xampp''htdocs''PhpExcel''index.php 在第 24 行
注意:尝试在第 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>
您的文件无法上传。
检查一下,看看是什么导致了你的错误:
// 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.');
}
这应该可以让您了解错误