Priti's Technical Corner

April 26, 2014

MongoDB – Beginner tutorial


Hello Friends, I have added another beginner tutorial slides related to Mongo.

Hope you find it helpful. If you feel something missing at beginner level – I am open to suggestion to improve the tutorials for basic.

Advertisements

April 8, 2014

Download Excel Sheet in Zf2

Filed under: PHP, Zend framework, ZF2 — Tags: , — pritisolanki @ 5:05 pm

 

$response = new \Zend\Http\Response\Stream();
$response->setStream(fopen($myfile, ‘r’)); //read file which you want to download as xls
$response->setStatusCode(200);

$headers = new \Zend\Http\Headers();
$headers->addHeaderLine(“Content-Type: application/vnd.ms-excel; charset=UTF-8”)
->addHeaderLine(‘Content-Disposition’, ‘attachment; filename=my.xls’)
->addHeaderLine( “Content-Transfer-Encoding: binary” )
->addHeaderLine(‘Content-Length’, filesize($myfile));
$response->setHeaders($headers);

There are some cases when you will see extra row in downloaded sheet in header section. To remove those extra empty lines in the downloaded sheet add ob_end_clean();  In start of above code.

Hope this little trick help some of the needy one !

Blog at WordPress.com.

%d bloggers like this: