Skip to content


PHPExcel在php5.2.10上的bug

Fatal error: Class ‘PHPExcel_Worksheet’ not found in /htdocs/webapp/includes/libs/PHPExcel.php on line 114

PHPExcel.php第114行内容

$this->_workSheetCollection[] = new PHPExcel_Worksheet($this);

PHPExcel使用了自动载入class
PHPExcel/Autoloader.php 第43行输入调试代码

echo $pObjectFilePath;
var_dump(file_exists($pObjectFilePath));
echo “
“;

if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {
return false;
}


/htdocs/webapp/includes/libs/PHPExcel/Shared/ZipStreamWrapper.phpbool(true)
/htdocs/webapp/includes/libs/PHPExcel/Worksheet.phpbool(false)

Fatal error: Class ‘PHPExcel_Worksheet’ not found in /htdocs/webapp/includes/libs/PHPExcel.php on line 114

Worksheet.php文件没有存在?
反复检查了php中open_basedir,文件及目录权限,zip扩展,pear都没问题.
并在autoloader前用代码测试文件确实可以检测到.

var_dump(file_exists(‘/htdocs/webapp/includes/libs/PHPExcel/Worksheet.php’));

试了下把ZipStreamWrapper.php禁止载入后就可顺利通过.
注释PHPExcel.php第34行内容

PHPExcel_Autoloader::Register();
//PHPExcel_Shared_ZipStreamWrapper::register();

看来问题确实在这里,再用代码确认下是stream_register_wrapper和file_exists的bug

class VariableStream {
var $position;
var $varname;

function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url[“host”];
$this->position = 0;

return true;
}

function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}

function stream_write($data)
{
$left = substr($GLOBALS[$this->varname], 0, $this->position);
$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
$GLOBALS[$this->varname] = $left . $data . $right;
$this->position += strlen($data);
return strlen($data);
}

function stream_tell()
{
return $this->position;
}

function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}

function stream_seek($offset, $whence)
{
switch($whence) {
case SEEK_SET:
if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
$this->position = $offset;
return true;
} else {
return false;
}
break;

case SEEK_CUR:
if ($offset >= 0) {
$this->position += $offset;
return true;
} else {
return false;
}
break;

case SEEK_END:
if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
$this->position = strlen($GLOBALS[$this->varname]) + $offset;
return true;
} else {
return false;
}
break;

default:
return false;
}
}
}

var_dump(file_exists(‘/htdocs/webapp/includes/libs/PHPExcel.php’));

stream_register_wrapper(“var”, “VariableStream”)
or die(“Failed to register protocol”);
var_dump(file_exists(‘/htdocs/webapp/includes/libs/PHPExcel.php’));


输出结果

bool(true) bool(false)

解决方法:
1.注释PHPExcel.php第34行内容
PHPExcel_Shared_ZipStreamWrapper::register();

2.更换php版本
目前换成php.5.2.14没有问题

Posted in PHP, 技术.

Tagged with , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.