Read old excel xls using php - php

I try to read excel file format slx by php code i use SimpleXLS class but i get error :
Fatal error: Uncaught Error: Class 'SimpleXLS' not found in C:\laragon\www\xls\examples\01-basic_usage.php:5
Stack trace:
#0 {main}
thrown in C:\laragon\www\xls\examples\01-basic_usage.php on line 5
Here is the page code, which is the original code for the page :
<?php /** #noinspection ForgottenDebugOutputInspection */
require_once __DIR__ . '/SimpleXLS.php';
echo '<h1>Parse books.xsl</h1><pre>';
if ( $xls = SimpleXLS::parse('books.xls') ) {
print_r( $xls->rows() );
} else {
echo SimpleXLS::parseError();
}
echo '<pre>';
when i use SimpleXLSX class with file xlsx it's work but xls not work
https://github.com/shuchkin/simplexls
any help?

Related

PdfParser issue in PHP

Thank you in advance
I am using the PdfParser library to extract text from PDF
My current code for that is as below
$parser = new \Smalot\PdfParser\Parser();
$pdfsource = $parser->parseFile($dest_path);
$pages = $pdfsource->getPages();
foreach ($pages as $page) {
$final_text.=strtolower(str_replace(' ', '', $page->getText()));
}
It is working well but for some PDF getting below Exception
Fatal error: Uncaught Exception: Object list not found. Possible secured file. in /var/www/html/pdfparser-master/vendor/smalot/pdfparser/src/Smalot/PdfParser/Parser.php:102 Stack trace: #0

I can't solve this Fatal error problem with pdfMerger

I'm trying to merge some pdf's, but I have a problem that I can't understand and I don't know what's happening, Can someone help me?
Attached code in PHP
This is the method for pdfMerger
public static function pdfMerger($archivos, $destino){
$pdf = new PDFMerger(); // or use $pdf = new \PDFMerger; for Laravel
if($archivos != null){
for($i=0; $i < count($archivos); $i++){
$pdf->addPDF($archivos[$i], 'all');
}
}
$pdf->merge('file', $destino);
}
And here is where I'm calling the method:
//This is a test
$control = new FilesController();
$dir = "/Jomar/induccion/documents/";
$files = glob($_SERVER['DOCUMENT_ROOT']."{$dir}politicas empresa/*.pdf");
$url = $_SERVER['DOCUMENT_ROOT']."{$dir}politicas empresa/prueba.pdf";
print_r($files);
$control->pdfMerger($files, $url);
This is the error I'm currently receiving:
Fatal error: Uncaught Exception: TCPDF_PARSER ERROR: decodeFilterFlateDecode: invalid code in C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\include\tcpdf_filters.php:474 Stack trace: #0 C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\include\tcpdf_filters.php(359): TCPDF_FILTERS::Error('decodeFilterFla...') #1 C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\include\tcpdf_filters.php(94): TCPDF_FILTERS::decodeFilterFlateDecode('\xEA\x91\xB9mj/\xAB\x8E;iN\xA3\x143\xAF...') #2 C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\tcpdi_parser.php(1310): TCPDF_FILTERS::decodeFilter('FlateDecode', '\xEA\x91\xB9mj/\xAB\x8E;iN\xA3\x143\xAF...') #3 C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\tcpdi_parser.php(1249): tcpdi_parser->_rebuildContentStream(Array) #4 C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\tcpdi.php(192): tcpdi_parser->getContent() #5 C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\PDFMerger.php(104): TCPDI->importPage(1) in C:\xampp\htdocs\Jomar\induccion\config\PDFMerger-master\tcpdf\include\tcpdf_filters.php on line 474
(Sorry for my english)
The problem was of the permissions of the pdf, therefore, is necessary to check that in the pdf document doesn't have any type of restrictions. thanks for your help.

PHP Not detecting class properlly

For some reason it's not detecting the class files in the specified directory.
I'm unsure what the problem is here. Could anyone brighten this up for me?
Code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class main
{
public static
$test;
}
foreach(glob($_SERVER['DOCUMENT_ROOT'].'/engine/*.php') as $file) {
include($file);
}
main::$test = new Test();
?>
As you can see i'm trying to include all php files from /engine.php/*
Project file structure:
http://prntscr.com/hutqyo
But I'm getting the error
Fatal error: Uncaught Error: Class 'Test' not found in C:\xampp\htdocs\includes\loader.php:23 Stack trace: #0 {main} thrown in C:\xampp\htdocs\includes\loader.php on line 23
Here is my test.class.php code there isn't a lot in it yet. As i'm still working on this current problem:
<title>test</title>
<?php
class Test
{
function getIP(){
}
}
?>
Thanks to anyone that could possibly help me find the solution!

Autoload error in php

I am trying autoload function in php. The files are all in the same directory.
I have a file called aviation.php with the following code:
class Avaitor{
public function __construct(){
echo "Fly high<br>";
}
}
Then in my autoloader file I am trying to do this:
function __autoload($fileName){
if(file_exists($fileName . ".php"))
require_once $fileName . ".php";
}
//require_once "aviatior.php";
$pilot = new Avaitor();
But I am getting this error:
Fatal error: Uncaught Error: Class 'Avaitor' not found in
/Applications/MAMP/htdocs/php_oop/autoload.php:22 Stack trace: #0
{main} thrown in /Applications/MAMP/htdocs/php_oop/autoload.php on
line 22
Just to test that require_once does find my aviator.php I tried it out and then commented it out.
What am I doing wrong here?

How to import data from excel to mysql database using php

I am using PHPExcel to import a XLSX file to my related database. But while running the function I am getting the error. My code looks like shown below.
Controller:
<?php if (!defined ('BASEPATH')) exit ('No direct access allowed');
class ExcelController extends CI_Controller
{
public function index()
{
//load library excel
$this->load->library('excel');
//Here i used microsoft excel 2007
$objReader= PHPExcel_IOFactory::createReader('Excel2007');
//Set to read only
$objReader->setReadDataOnly(true);
//Load excel file
$objPHPExcel=$objReader->load('data.xls'); // error in this line
$objWorksheet=$objPHPExcel->setActiveSheetIndex(0);
//load model
$this->load->model('user_model');
//loop from first data untill last data
for($i=2;$i<=77;$i++)
{
$name= $objWorksheet->getCellByColumnAndRow(0,$i)->getValue();
$address= $objWorksheet->getCellByColumnAndRow(1,$i)->getValue();
$data_user=array('name'=>$name, 'username'=>$address);
$this->user_model->add_data($data_user);
}
}
}
?>
model:
<?php
if (!defined ('BASEPATH')) exit ('No direct access allowed');
class User_model extends CI_Controller
{
public function __construct() {
parent::__construct();
}
public function add_data($data_user)
{
$this->load->database();
$this->db->insert('data',$data_user);
return $this->db->insert_id();
}
}
?>
Error in my code:
Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open data.xls for reading! File does not exist.' in C:\xampp\htdocs\ci_excel\application\third_party\PHPExcel\Reader\Excel2007.php:347 Stack trace: #0 C:\xampp\htdocs\ci_excel\application\controllers\excelcontroller.php(19): PHPExcel_Reader_Excel2007->load('data.xls') #1 [internal function]: ExcelController->index() #2 C:\xampp\htdocs\ci_excel\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #3 C:\xampp\htdocs\ci_excel\index.php(202): require_once('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\ci_excel\application\third_party\PHPExcel\Reader\Excel2007.php on line 347
Judging by the error message and your comment, it looks like you are using an incorrect filepath.
$objPHPExcel=$objReader->load('data.xls');
In CodeIgniter paths are relative to the entry script, usually index.php.
Use a relative file path to this location or alternatively an absolute path.
I think you used incorrect path , change this
$objPHPExcel=$objReader->load('data.xls'); // error in this line
To
$objPHPExcel=$objReader->load('./application/third_party/Excel5/data.xlsx');

Categories