weird bug

Jan 14, 2011 at 3:52 PM

I am often getting


PHP Fatal error:  Uncaught exception 'Exception' with message 'Could not close zip file cache/DailyReport_14012011.xlsx.' in /var/www/html/dailyreport/classes/PHPExcel/Writer/Excel2007.php:340
Stack trace:
#0 /var/www/html/dailyreport/excel_creation.php(809): PHPExcel_Writer_Excel2007->save('cache/DailyRepo...')
#1 /var/www/html/dailyreport/cronjobs/customers_stats_new_live.php(311): require_once('/var/www/html/d...')
#2 {main}
  thrown in /var/www/html/dailyreport/classes/PHPExcel/Writer/Excel2007.php on line 340

i know its a problem in the $objExcel itself and not in the writing process.

The weird bit is that if i undo back to where i know it was working, i still get the error.

 

Jan 14, 2011 at 9:17 PM

Hello,

I just has this error and it was because the path where I wanted to save the file didn't exist...

Regards

Coordinator
Jan 14, 2011 at 9:47 PM

@Zick

You're right! This error will generally only occur if the directory path doesn't exist, or if your PHP doesn't have sufficient privileges to access the filepath or any existing file (if overwriting a file)

Jan 18, 2011 at 7:58 AM

ok after fiddling about with this, the reason is  i was not using the full path.

If i use $objWriter->save('cache/'.$filename);

it dies with the following error

PHP Fatal error:  Uncaught exception 'Exception' with message 'Could not close zip file cache/DailyReport_18012011.xlsx.' in /var/www/html/dailyreport/classes/PHPExcel/Writer/Excel2007.php:340
Stack trace:
#0 /var/www/html/dailyreport/excel_creation.php(1304): PHPExcel_Writer_Excel2007->save('cache/DailyRepo...')
#1 /var/www/html/dailyreport/cronjobs/customers_stats_new_live.php(314): require_once('/var/www/html/d...')
#2 {main}
  thrown in /var/www/html/dailyreport/classes/PHPExcel/Writer/Excel2007.php on line 340

 

If i use $objWriter->save('/var/www/html/dailyreport/cache/'.$filename);

everything is fine.

Coordinator
Jan 18, 2011 at 4:18 PM

'cache/'.$filename would be relative to the executing script's current working directory; '/var/www/html/dailyreport/cache/'.$filename is explicit from the filesystem root. The relative reference would only be valid if the script's cwd was /var/www/html/dailyreport so perhaps it's executing with a different cwd.

Jan 19, 2011 at 7:37 AM

thats part of the weird bit to be honest.

 

The script was and is sitting in /var/www/html/dailyreport, also the cache/'.$filename has DEFINATELY worked several times already, but after i have made changes in the script, it then sometimes failed.

I'm not sure exactly where the problem is, but using the full path seems to have solved it at the moment

 

Coordinator
Jan 19, 2011 at 8:05 AM

The directory where the script file is located, and the directory where PHP is running aren't necessarily the same... you can use PHP's getcwd() function to identify the current working directory when PHP is executing.