Reputation: 167
i'm trying to read from an excel file for the first time and i'm having some problems. I'm using PhpExcel library and i'm using the following code, now the excel file is uploaded in the folder but its not showing any data of excel file, and its giving error
"Error is catchedCould not open C:\xampp\tmp\phpF85B.tmp for reading! File does not exist."
And Notices like
Notice: Undefined variable: obj in C:\xampp\htdocs\PhpExcel\index.php on line 24
Notice: Trying to get property of non-object in C:\xampp\htdocs\PhpExcel\index.php on line 24
And finally
Fatal error: Call to a member function toArray() on a non-object in C:\xampp\htdocs\PhpExcel\index.php on line 24
<?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>
Upvotes: 0
Views: 749
Reputation: 6836
Your file can't be uploaded.
Check with this and see what is causing your error:
// 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.');
}
This should give you an idea about the error
Upvotes: 1