-
Currently I'm using Datatable to fill in all my data into a table format. I have an external button for exporting the selected entries in an Excel format. Now the following code does put all my data in an Excel sheet, but never displays it to the user. The sheet is stored in my C:\Xammp\htdocs folder and not downloads folder for some reason. AJAX call:
Controller:
I want it to be saved in the users download folder or atleast display it when the user exports it. As of now if it is deployed in the server and not localhost, I cant even get it on my C:\Xammp\htdocs folder. I've also tried $writer->save('php://output');, but it didn't save my folder, instead it gave a response like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can't control where the file will be saved in the client users machine; but you do need to send it to $writer->save('php://output'); However, that alone simply tells it to send the file data to he user's browser, which results in the
that you see... that's the stream of excel file data You also need to tell the browser that what you're sending is a stream of Excel file data rather than a stream of html data, by sending the appropriate headings to their bowser before yo send the filestream. // Redirect output to a client’s web browser (Xls)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="listings.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$writer->save('php://output'); I'd suggest spending a bit of time reading the documentation if you aren't that familiar with the way browser protocols work. |
Beta Was this translation helpful? Give feedback.
You can't control where the file will be saved in the client users machine; but you do need to send it to
php://output
usingHowever, that alone simply tells it to send the file data to he user's browser, which results in the
that you see... that's the stream of excel file data
You also need to tell the browser that what you're sending is a stream of Excel file data rather than a stream of html data, by sending the appropriate headings to their bowser before yo send the filestream.
// …