Magento – How to save the PDF file into Magento root folder

directorypdfsave

 $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoicesSet);
                $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
'.pdf', $pdf->render(), 'application/pdf');   

I am trying to download all invoice in PDF and need to Save in Magento root folder.

But it's downloading in browser only.

Can any one help for this issue.

Best Answer

This

 $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s'). '.pdf', $pdf->render(), 'application/pdf'); 

would send it to the browser. The below would write to a file in the var directory instead:

$name = 'invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s'). '.pdf';
file_put_contents(Mage::getBaseDir('var').DS.$name,$pdf->render());