Call to a member function setTempDir() on a non-object

Sep 28, 2009 at 9:08 AM

Hi everyone,

I am very new to this.

I got this error:

$objWriter->setTempDir("C:\");

Notice: Undefined variable: objWriter in C:\xampp\htdocs\phptoexcel\ztest2.php on line 44

Fatal error: Call to a member function setTempDir() on a non-object in C:\xampp\htdocs\phptoexcel\ztest2.php on line 44

I wanted to save to a specific directory, how can I do that?

 

Cheers,

felix

Coordinator
Sep 28, 2009 at 9:49 AM

The error message suggests that you haven't yet instantiated $objWriter

 

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('/path/to/file.xlsx');
Sep 28, 2009 at 9:55 AM
Edited Sep 28, 2009 at 9:56 AM
MarkBaker wrote:

The error message suggests that you haven't yet instantiated $objWriter

 

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('/path/to/file.xlsx');

Hi MarkBaker,

Thank you for the fast reply, I have not solved the temp directory problem however, I could save to a specific directory.

Is there anyway for me when a user run a script it will run save as instead of automatically save to a specific drive?

Meaning if I Click a button it will go like save as instead of directly save.

 

Coordinator
Sep 28, 2009 at 10:07 AM

Do you mean that you're trying to open a save dialogue box in the client's browser?

If so, look to section 4.4.34 of the PHPExcel developers ducumentation entitled "Redirect output to a client’s web browser"

Sep 28, 2009 at 10:42 AM

Thank you very much MarkBaker!

I haven't read until that part!

I have another problem when testing to my server, previously it was working fine when i put the PHPExcel files and classes under the same directory now I have problems detecting @@, this time I will try to solve it myself first!

 

Cheers,

felix