1

我正在使用 XAMP 运行的 Windows XP 上测试Flexpaper插件,问题是它不显示 pdf,检查它说的 php 错误日志:

PHP 致命错误:在第 24 行调用 C:\xampp\htdocs\PDFViewer\php\services\view.php 中未定义的方法 Config::getConfig()

文件夹结构为:(省略不相关文件)

htdocs/
    |->PDFViewer/
        |->php/
            |->admin_files/
            |->config/
                |->config.ini.win.php
            |->lib/
                |->common.php
                |->pdf2json_php5.php
                |->pdf2swf_php5.php
                |->config.php
            |->services/
                |->view.php

view.php 代码片段

require_once("../lib/common.php");
require_once("../lib/pdf2swf_php5.php");
require_once("../lib/swfrender_php5.php");
require_once("../lib/pdf2json_php5.php");

pdf2json_php5.php 的代码片段

require_once("config.php");
require_once("common.php");

pdf2swf_php5.php 的代码片段

require_once("config.php");
require_once("common.php");

swfrender_php5.php 的代码片段

require_once("config.php");
require_once("common.php");

在你问之前,是的,config.php 确实有 getConfig 方法


编辑:添加了 config.php

<?php date_default_timezone_set('America/New_York'); ?>
<?php
class Config{
  protected $config;

    public function __construct()
    {
        if (!defined('ROOT')) {
            define('ROOT', dirname(dirname(dirname(__FILE__))));
        }

        if (!defined('APP_DIR')) {
            define('APP_DIR', basename(dirname(dirname(__FILE__))));
        }   

        if( PHP_OS == "WIN32" || PHP_OS == "WINNT"  )
            $this->config = parse_ini_file($this->getConfigFilename());
        else
            $this->config = parse_ini_file($this->getConfigFilename());
    }

    public function getConfigDir(){
        if( PHP_OS == "WIN32" || PHP_OS == "WINNT"  )
            return dirname(__FILE__) . '\\..\\config';
        else
            return dirname(__FILE__) . '/../config'; 
    }

    public function getConfigs(){
        return $this->config;
    }

    public function getConfig($key = null)
    {
      if($key !== null)
      {
        if(isset($this->config[$key]))
        {
          return $this->config[$key];
        }
        else
        {
          return null;
        }
      }
      else
      {
        return $this->config;
      }
    }

    public function setConfig($config)
    {
      $this->config = $config;
    }

    public function getDocUrl(){
        return "<br/><br/>Click <a href='http://flexpaper.devaldi.com/docs_php.jsp'>here</a> for more information on configuring FlexPaper with PHP";
    }

    public function getConfigFilename(){
        if( PHP_OS == "WIN32" || PHP_OS == "WINNT"  )
            return ROOT . '\\' . APP_DIR . '\\config\\config.ini.win.php';
        else
            return ROOT . '/' . APP_DIR . '/config/config.ini.nix.php';
    }

    public function saveConfig($array){
        $this->write_php_ini($array,$this->getConfigFilename());
    }

    function write_php_ini($array, $file)
    {
        $res = array();
        foreach($array as $key => $val)
        {
            if(is_array($val))
            {
                $res[] = "[$key]";
                foreach($val as $skey => $sval) {
                    $sval = str_replace("\"","\\\"",$sval);
                    $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
                }
            }
            else {
                $val = str_replace("\"","\\\"",$val);
                $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
            }
        }
        $this->safefilerewrite($file, implode("\r\n", $res));
    }

    function safefilerewrite($fileName, $dataToSave)
    {   
        $dataToSave = "; <?php exit; ?> DO NOT REMOVE THIS LINE\r\n" . $dataToSave;

        if ($fp = fopen($fileName, 'w'))
        {
            $startTime = microtime();
            do
            {  
               $canWrite = flock($fp, LOCK_EX);

               // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
               if(!$canWrite) usleep(round(rand(0, 100)*1000));
            } while ((!$canWrite)and((microtime()-$startTime) < 1000));

            //file was locked so now we can store information
            if ($canWrite)
            {            fwrite($fp, $dataToSave);
                flock($fp, LOCK_UN);
            }
            fclose($fp);
        }else{
            throw new Exception('Cant write to config ' . $fileName);
        }

    }   
}
4

2 回答 2

0

看起来我在添加C:/xampp/htdocsinclude_pathphp.ini 中的变量后让它工作了,然后只修改了 require_once 函数。

View.php 中的 require_once 部分如下所示:

require_once("PDFViewer/php/lib/common.php");
require_once("PDFViewer/php/lib/pdf2swf_php5.php");
require_once("PDFViewer/php/lib/swfrender_php5.php");
require_once("PDFViewer/php/lib/pdf2json_php5.php");

对于pdf2swf_php5.php,swfrender_php5.php和 也是如此pdf2json_php5.php

于 2012-12-20T21:58:03.517 回答
0

修改view.php的代码片段为:

$ds = DIRECTORY_SEPARATOR;
require_once("..{$ds}lib{$ds}common.php");
require_once("..{$ds}lib{$ds}pdf2swf_php5.php");
require_once("..{$ds}lib{$ds}swfrender_php5.php");
require_once("..{$ds}lib{$ds}pdf2json_php5.php");
于 2012-12-20T04:50:52.430 回答