PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Structures » OLE » Bug #483

_FILEH_ never opened

Details

Submitted2003-12-23 03:33 UTC
Fromspammable at howsfamily dot net
StatusDuplicate
PackageOLE
PHP Version4.3.4
OSWindows XP Pro
Roadmaps(Not assigned)

Comments

[2003-12-23 03:33 UTC] spammable at howsfamily dot net

Description:
------------
I had a problem on my system with another PEAR module creating 0-byte files. It turned out that the problem was that the OLE library, which it depended on, reported an error opening a temporary file.

When I looked through the OLE code in Root.php, I found a number of references to $this->_FILEH_, but I never found a place where this was assigned to.

I added the line

$this->_FILEH_ = fopen($this->_tmp_filename, "r+w");

at line 100 in Root.php, and everything worked. I'm not sure if this is idiosyncratic to my own system, or more widespread. It strikes me as a very obvious bug.

[2003-12-23 10:57 UTC] xnoguer at php dot net

What version of OLE are you using? The latest version of OLE has this line on Root.php:

$this->_FILEH_ = @fopen($this->_tmp_filename,"w+b");

[2003-12-23 12:21 UTC] spammable at howsfamily dot net

I'm using OLE 0.5, and you're right, that line does exist. My only interaction OLE is through the a third party module, Spreadsheet_Excel_Writer, so I haven't really gone through the depths of it. But the line you refer to occurs in an "else" clause:

//Lines 97-107
if (($filename == '-') or ($filename == ''))
...
else
{
$this->_FILEH_ = @fopen($filename, "wb");
...
}

However, the section in the "if" clause still makes reference to _FILEH_:

//Line 101-102
if ($this->_FILEH_ == false)
return $this->raiseError("Can't create temporary file.");

Without _FILEH_ being assigned to, this will always be falsem and thus always raise the error.

As I said, I haven't really gone through your code, so it simply may be that the excel module invokes your code incorrectly, but I found that adding a line to open the file in the "if" clause solved my problem. I'm not sure if it translates from my specific problem to the general case.

[2003-12-24 10:30 UTC] xnoguer at php dot net

The if block is:

if (($filename == '-') or ($filename == ''))
{
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = @fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) {
return $this->raiseError("Can't create temporary file.");
}
}

so $this->_FILEH_ does get assigned anyway. Only problem is, if you don't have permissions for the default temp dir and haven't set another dir with setTempDir() it will fail.

I know that if you are using Spreadsheet_Excel_Writer you don't have a way to set the temp dir to be used by OLE (yet). I'm the maintainer for Spreadsheet_Excel_Writer too, and there is a setTempDir() method in cvs, but I can't make a release now.
Please check my answer to bug #482. If that solves your problem I'll close this bug and keep that one open.

[2003-12-24 10:43 UTC] spammable at howsfamily dot net

Yes, I edited my copy of Spreadsheet_Excel_Writer to set the temporary directory. If the "if" clause you quoted is right, it looks like I must have accidentally modified my copy when I was dicking around with getting it to work. Sorry about that, feel free to close the bug.