In my PHP project, a PDF is generated in a call to a fpdf extended file, and an XLS is generated by a phpxls library dependent file.
I have called chdir("libs/phpxls");
inside the XLS generator file. When PDF generator file is called (which has nothing to do with xls generator or its libs), an error is shown due to the chdir("libs/phpxls");
called in the XLS generator. I haven't called the xls generator file anywhere.
Does anyone know what is going on..?
The getcwd();
function returns the current directory as inside /libs/phpxls
, as if its calling the XLS generator, even if my code or any of the libs aren't calling it directly or indirectly.
Is all the files respective chdir()
, include()
, require()
functions called by the PHP interpreter by itself..?
The problem gets solved after I changed the base directory to the real one using chdir('../..');
But I don't have any idea why is the file even called when its not meant to be..?
EDIT
I have used chdir(APP_REAL_PATH.'libs/phpxls'); in XLS generator.
when the pdf generator file is called, this is the error shown.
Warning: getimagesize(images/rupee-symbol.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:"location"\services\libs\fpdf\fpdf.php on line 1213
FPDF error: Missing or incorrect image file: images/rupee-symbol.jpg
But after there is no direct or indirect relation b/w these two files or their respective libs.
Even if I have commented out all the calls to the XLS generator in my project, the error still comes.
But once I did get back to the parent directory via chdir(../..)
in the XLS generator, I was able to make a call to the pdf generator without a problem.
Here actually my problem is solved by doing so. But still I don't understand why an uncalled file is changing the directory...?
Code Samples*
class PdfInvoiceReport extends FPDF {
var $companyName;
var $companyAddress;
var $serviceTaxNo;
var $storedPanNo;
var $invNotes;
var $objGeneral;
var $roundedNetAmt;
function __construct($invId){
parent::__construct();
//$this->cust = $cust;
// $this->type = $type;
echo getcwd();
$this->AliasNbPages();
$this->AddPage();.....
In my project, the front-end is flex. when the pdf button is clicked, the file containing the above class is called directly. So this is where I should checking the directory and I,m doing it in the constructor. It returns the directory of the xls library.
Now the xls generator file code parts
<?php
//documentation on the spreadsheet package is at:
//http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php
include_once('init\init.php');
include_once(APP_REAL_PATH.'ReportsService.php');
include_once(APP_REAL_PATH.'classes\general_class.php');
include_once(APP_REAL_PATH.'classes\customer_class.php');
chdir(APP_REAL_PATH.'libs/phpxls');
require_once 'Writer.php';
//chdir('../..');
class XlsGenericReport {
var $objExcelWriter;
function __construct($allArray){
$sheet1 = $allArray['headerNames'];
$sheet2 = $allArray['data'];
$this->prepareXls($sheet1,$sheet2);
}............
This file is called directly when the xls generation button is clicked from the UI.
there is nothing more in it.