doulianqi3870 2011-12-02 11:27
浏览 29

包含chdir()的未调用文件导致错误

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法