write excel5 works on local windows but not remote unix

Topics: User Forum
Aug 30, 2009 at 2:22 PM

On my local Windows development pc (WAMP) all works fine and I can use either

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

or

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

On my remote server running redhat only 2007 works.  Excel5 doesn't show an error, it just stops at the "save" stage.  I'm using "01simple.php" as a test.

Is something extra required on my remote server?

Regards

Mark

Developer
Aug 30, 2009 at 2:30 PM

Are you getting any error messages? Try to add this at the beginning of the script and see if you get any messages:

error_reporting(E_ALL);
ini_set('display_errors', '1');

Aug 30, 2009 at 2:38 PM

Thanks

Loads now!


Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 299

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 300

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 87

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 88

Fatal error: Uncaught exception 'Exception' with message 'Can't create temporary file' in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php:90 Stack trace: #0 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php(580): PHPExcel_Shared_OLE_PPS_File->init() #1 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php(548): PHPExcel_Writer_Excel5_Workbook->_storeOLEFile() #2 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php(233): PHPExcel_Writer_Excel5_Workbook->_storeWorkbook() #3 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5.php(127): PHPExcel_Writer_Excel5_Workbook->close() #4 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Tests/sample2-generate.php(288): PHPExcel_Writer_Excel5->save('../data/top5000...') #5 {main} thrown in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 90

 

Developer
Aug 30, 2009 at 3:05 PM

From the line numbers in those messages it looks like you are using PHPExcel 1.6.7. Can you pehaps try to upgrade to PHPExcel 1.7.0 and post back the results?

Aug 30, 2009 at 8:54 PM

I've uploaded 1.7.0 and get the same?

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 346

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 347

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 95

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 96

Fatal error: Uncaught exception 'Exception' with message 'Can't create temporary file' in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php:98 Stack trace: #0 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Writer/Excel5.php(190): PHPExcel_Shared_OLE_PPS_File->init() #1 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Tests/sample2-generate.php(288): PHPExcel_Writer_Excel5->save('../data/top5000...') #2 {main} thrown in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 98

 

 

Developer
Aug 30, 2009 at 9:02 PM

I need your help to debug this. Can you locate line 346 in Classes/PHPExcel/Writer/Excel5/Worksheet.php and replace this:

$fileName = tempnam($this->_tmp_dir, 'XLSHEET');

with this:

var_dump($this->_tmp_dir);
$fileName = tempnam($this->_tmp_dir, 'XLSHEET');
var_dump($fileName);
exit;

Afterwards, post back the result of the output.

Aug 30, 2009 at 9:07 PM

Get this

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 299

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 300

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 87

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 88

Fatal error: Uncaught exception 'Exception' with message 'Can't create temporary file' in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php:90 Stack trace: #0 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php(580): PHPExcel_Shared_OLE_PPS_File->init() #1 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php(548): PHPExcel_Writer_Excel5_Workbook->_storeOLEFile() #2 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php(233): PHPExcel_Writer_Excel5_Workbook->_storeWorkbook() #3 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Writer/Excel5.php(127): PHPExcel_Writer_Excel5_Workbook->close() #4 /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Tests/sample2-generate.php(288): PHPExcel_Writer_Excel5->save('../data/top5000...') #5 {main} thrown in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 90

 

Developer
Aug 30, 2009 at 9:12 PM

Hmm.. Can you check again if you have edited it right? Looks like you have switched back to 1.6.7 again?

Aug 30, 2009 at 9:20 PM

Oops - it's late

string(0) ""
Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 347
bool(false)

 

Developer
Aug 30, 2009 at 9:25 PM

Ok, the script cannot write temporary files. What output do you get for this simple script?

<?php
var_dump(sys_get_temp_dir());
exit;
?>

Aug 30, 2009 at 9:28 PM

string(4) "/tmp"

 

Developer
Aug 30, 2009 at 9:34 PM

Ok, and what do you get for this last test, just to double check:

<?php
$filename = tempnam('', 'XLS');
var_dump($filename);

$filename = tempnam(sys_get_temp_dir(), 'XLS');
var_dump($filename);
?>

Aug 30, 2009 at 9:37 PM

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/var/www/vhosts/top5000contacts.com/httpdocs:/tmp) in /var/www/vhosts/top5000contacts.com/httpdocs/includes/phpexcel2/Tests/tempdir.php on line 12
bool(false) string(14) "/tmp/XLSh1m3d3"

 

Developer
Aug 30, 2009 at 9:49 PM

At line 126 in Classes/PHPExcel/Writer/Excel5.php (PHPExcel 1.7.0), can you try to change this

    public function __construct(PHPExcel $phpExcel) {
$this->_phpExcel = $phpExcel;
$this->_BIFF_version = 0x0600;
$this->_tempDir = '';



to this:

    public function __construct(PHPExcel $phpExcel) {
$this->_phpExcel = $phpExcel;
$this->_BIFF_version = 0x0600;
$this->_tempDir = sys_get_temp_dir();


Let us know if it solves the problem?

Aug 30, 2009 at 9:55 PM

It fixes it.

Thank you very much for your help with this.  I will definitely make a donation when this goes live!

Regards

 

Developer
Aug 30, 2009 at 9:58 PM
Edited Aug 31, 2009 at 2:12 AM

That's great! I will follow up on this with a fix in SVN so it is available in source code release tomorrow from here:

http://phpexcel.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Edit:

Link to work item: http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10560

Aug 30, 2009 at 10:08 PM

Actually no point in waiting - I've just made the donation.

Best regards

 

Nov 3, 2009 at 4:25 PM
Edited Nov 3, 2009 at 4:55 PM

Hello,

I downloaded the newest version of PHPExcel, but I still got this error:

 

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/g41157/***.com) in /var/www/g41157/***.com/HTML/phpexcel2/Classes/PHPExcel/Writer/Excel5/Worksheet.php on line 355

Warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/g41157/***.com) in /var/www/g41157/***.com/HTML/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 80

Fatal error: Uncaught exception 'Exception' with message 'Can't create temporary file' in /var/www/g41157/***.com/HTML/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php:98 Stack trace: 
#0 /var/www/g41157/***.com/HTML/phpexcel2/Classes/PHPExcel/Writer/Excel5.php(198): PHPExcel_Shared_OLE_PPS_File->init() 
#1 /var/www/g41157/***.com/HTML/includes/classes/grabberexcel.class.php(158): PHPExcel_Writer_Excel5->save('xls/6a42f855037...') 
#2 /var/www/g41157/***.com/HTML/index.php(379): grabberexcel->generateExcel() 
#3 {main} thrown in /var/www/g41157/***.com/HTML/phpexcel2/Classes/PHPExcel/Shared/OLE/OLE_File.php on line 98

 

 

Can you help me with this?

Thanks a lot!

Btw:

That's when I run this code:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpexcel2/Classes/');

/** PHPExcel */
include 'PHPExcel.php';

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
include 'PHPExcel/Writer/Excel5.php';

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$sFileName = md5(rand(0,200) . rand(400, 3000));
$objWriter->save('xls/' . $sFileName . '.xls');

 

When I run this, it just works:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpexcel2/Classes/');

/** PHPExcel */
include 'PHPExcel.php';

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
include 'PHPExcel/Writer/Excel5.php';

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$sFileName = md5(rand(0,200) . rand(400, 3000));
$objWriter->save('xls/' . $sFileName . '.xlsx');

 

 

Developer
Nov 4, 2009 at 1:19 AM

@brie:

This error is slightly different from the one that sparkyhd had. Here it looks like the server is configured unfortunately. The open_basedir restriction that has been set up is too restrictive.

If you check with phpinfo() you probably have something like this, right:

open_basedir /var/www/g41157/***.com

It should have looked like this so you at least also have access to the systems temporary directory

open_basedir /var/www/g41157/***.com:/tmp

For a start, can you check with the server administrator whether it is possible to modify php.ini ?

Nov 4, 2009 at 2:34 PM

Hi Koyama,

Thanks for your reply.
I asked my hosting wether I am allow to edit the php.ini file.
But they told me it was another problem:
I had to change sys_get_temp_dir() to '../tmp/' and it worked.

Thanks a lot!

Developer
Nov 4, 2009 at 11:48 PM
brie wrote:

Hi Koyama,

Thanks for your reply.
I asked my hosting wether I am allow to edit the php.ini file.
But they told me it was another problem:
I had to change sys_get_temp_dir() to '../tmp/' and it worked.

Thanks a lot!

Let's see whether your case is an exception or if others report about similar problems in the future.

I'm not so happy that you had to edit the library source code to get it working, it should work out of the box. I say we keep this thread open.

 

Feb 22, 2010 at 12:22 PM

Since my tmp directory on my web host is one level below the webroot, I added this:

        $findtmp = explode('/',$_SERVER['DOCUMENT_ROOT']);
        array_pop($findtmp);
        $findtmp = implode('/',$findtmp);
        $findtmp .="/tmp";

Replaced sys_get_temp_dir() with $findtmp, and it works where ever the generating script is.

 

Developer
Feb 22, 2010 at 3:41 PM
Baskvald wrote:

Since my tmp directory on my web host is one level below the webroot, I added this:

        $findtmp = explode('/',$_SERVER['DOCUMENT_ROOT']);
        array_pop($findtmp);
        $findtmp = implode('/',$findtmp);
        $findtmp .="/tmp";

Replaced sys_get_temp_dir() with $findtmp, and it works where ever the generating script is.

 

Oh, I should have mentioned that the use of temporary directory has been removed completely from Excel5 writer.

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=11692

There were just too many problems.

Try to test with latest source code:

http://phpexcel.codeplex.com/SourceControl/list/changesets

There should no longer be any problems related to temporary directories.

May 24, 2010 at 2:16 PM

PLZ HELP...

I need to load a template xls file write into it and save it back as an xls...

Here is a simple code that i tried

<?
/** Error reporting */
error_reporting(E_ALL);

/** PHPExcel */
require_once '../Classes/PHPExcel.php';

/** PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("template1.xls");

// Add some data
$objPHPExcel->setActiveSheetIndex(1)
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('test.xls');
?>

This is the error that is shown on the browser

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@piyush.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

 

Works fine when i use:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

what do i do? plz help

Coordinator
May 26, 2010 at 8:54 AM

It probably means that something is misconfigured on your server. Check that you have all required PHP extensions