我正在测试运行XAMP的Windows XP上的Flexpaper插件,问题是它没有显示pdf,检查它说的php错误日志:
PHP致命错误:调用未定义的方法Config :: getConfig() 第24行的C:\ xampp \ htdocs \ PDFViewer \ php \ services \ view.php
文件夹结构是:(省略不相关的文件)
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);
}
}
}
答案 0 :(得分: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");
答案 1 :(得分:0)
在将C:/xampp/htdocs
添加到php.ini中的include_path
变量之后,看起来我已经使它工作了,然后只修改了require_once函数。
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
。