[Vtigercrm-developers] Export to Excel

John Crisp john at reetspetit.net
Thu Oct 27 09:51:31 PDT 2011


Still trying to sort this small but irritating problem.

Following on from my previous I note that there are other users who have
suffered the same problem :

http://forums.vtiger.com/viewtopic.php?f=104&t=39503&p=126401
http://forums.vtiger.com/viewtopic.php?f=104&t=39377&p=126194

(5.1.0) but same problem
http://forums.vtiger.com/viewtopic.php?f=96&t=29369


Having read around a bit more I found these seem related :

http://pear.php.net/bugs/bug.php?id=16938&edit=12&patch=correct-open_basedir-check&revision=1261435638

http://pear.php.net/bugs/bug.php?id=16936

I'm not sure that it is an open_basedir error - that's just a misnomer.

I have a feeling that tempnam doesn't quite work as it should, but there
should be something in place to catch it when it fails.

For whatever reason, the $tmp_dir/_tempdir is not set, and tempnam fails
to find anywhere else to write too, though it should use the system temp
directory if all else fails but it doesn't see to find this.
sys_get_temp_dir() reports mine as /tmp

Anyway, in theory, if the file checks fail, the function (as shown below
- note the ToDo comment about warning when unable to create file) should
go on to load the sheet in memory, but it fails before it gets that far
as there is no test for tempnam failing.

Ran a quick test with open_basedir :
/home/e-smith/files/ibays/testbay/html/:/tmp/
tmp = /tmp

The following fails with an open_basedir error

$tmpfname = tempnam("/home/", "FOO");


So tempnam doesn't do exactly what it says on the tin, probably
depending on the flavour & setup of your server, and needs a proper
variable set.

The quick fix sets _tempdir to prevent the problem. But I'm sure that
this is not the best method.

I'd still love to know how do we get the $tmp_dir in CreateXL.php passed
to $tempdir in class.writeexcel_worksheet.inc.php as per my earlier post
below

Should this go as a bug in the trac ??? I'd like to get it sorted but
not sure of the best way to do it.


B. Rgds
John


function _initialize() {

    # Open tmp file for storing Worksheet data.
	//$this->_tempdir=sys_get_temp_dir();

	$this->_tmp_file_name = tempnam($this->_tempdir, "php_writeexcel");
    $fh=fopen($this->_tmp_file_name, "w+b");

    if ($fh) {
        # Store filehandle
        $this->_filehandle = $fh;
    } else {
        # If tempfile() failed store data in memory
        $this->_using_tmpfile = 0;

        if ($this->_index == 0) {
            $dir = $this->_tempdir;

//todo            warn "Unable to create temp files in $dir. Refer to
set_tempdir()".
//                 " in the Spreadsheet::WriteExcel documentation.\n" ;
        }
    }
}





On 22/10/11 00:38, John Crisp wrote:
> I have been trying to get this working but on both my test machine and
> my main system and I get the dreaded error :
> 
> class.writeexcel_worksheet.inc.php line 204 tempnam() [<a
> href='function.tempnam'>function.tempnam</a>]: open_basedir restriction
> in effect. File() is not within the allowed path(s):
> (/home/e-smith/files/ibays/testbay/html/)
> 
> class.writeexcel_worksheet.inc.php line 205 - fopen() [<a
> href='function.fopen'>function.fopen</a>]: Filename cannot be empty
> 
> 
> I have read as much as I can find on the subject as there have been
> others with the same situation. I have checked the permissions,
> PHPbasedir directives, and Safe Mode is off on both systems.
> 
> The above is from the test machine and the phpbasedir is set to
> /home/e-smith/files/ibays/testbay/html/   (I have several directories in
> this space)
> 
> The root directory is
> /home/e-smith/files/ibays/testbay/html/vtiger_521
> 
> 
> 
> It would seem that in CreateXL.php it creates the workbook without
> problems as the $tmp_dir gets passed in $fname
> 
> But when it goes to create the worksheet, it has no temporary directory
> set, checks with PHPBasedir and if that is not correct (no idea why it
> still doesn't like mine) then it will fail.
> 
> Effectively it fails at Line 21 in CreateXL.php once it gets to
> _initialize in class.writeexcel_worksheet.inc.php
> 
> 
>>From CreateXL.php :
> 
> 19 global $tmp_dir, $root_directory;
> 
> 21 $fname = tempnam($root_directory.$tmp_dir, "merge2.xls");
> 22 $workbook = &new writeexcel_workbook($fname);
> 23 $worksheet =& $workbook->addworksheet();
> 
> 
> So how do we get the $tmp_dir passed to  $tempdir in
> class.writeexcel_worksheet.inc.php assuming that I don't want to modify
> that file ?????
> 
> 
> This would appear to be one answer from a post in the forums but this
> means editing the class file, and surely it would be better to set the
> $tempdir properly  ???? Also, if the $tempdir is set properly, it would
> avoid the problems with the PHPbasedir ?
> 
> http://forums.vtiger.com/viewtopic.php?f=96&t=29369&hilit=open_basedir+class.writeexcel_worksheet.inc
> 
> "The problem is generated by open_basedir restrictions (normal php
> protection that some servers have active) We can avoid that using the
> sys_get_temp_dir() fucntion
> 
> to do it :go include\php_writeexcel\class.writeexcel_worksheet.inc.php
> just between line 200-203 to obtain:
> 
> Code: Select all
>     function _initialize() {
>        $this->_tempdir=sys_get_temp_dir();
>         # Open tmp file for storing Worksheet data.sys_get_temp_dir
>         $this->_tmp_file_name = tempnam($this->_tempdir, "php_writeexcel");
> "
> 
> However, I'm sure it must be possible by amending Line 23
> $worksheet =& $workbook->addworksheet();
> 
> I just don;t know how to do it !
> 
> Sorry for the long post and hope it makes sense. Any advice on this
> would be gratefully received - I've spent all day scratching my head on
> this and have hit a brick wall !!!!
> 
> 
> B. Rgds
> John
> _______________________________________________
> http://www.vtiger.com/




More information about the vtigercrm-developers mailing list