Issue
I'm using PHPExcel to generate excel files (crazy right ?) with information I get from a database, the thing is whenever I create the file it is saved in the server and then I just send a link to that file to the user so he can access it.
I doubt this is the right way of doing it, what I'm looking for is to just send the file to the browser without saving it on the server.
How do I output EXCEL file directly to user without storing locally?
Code:
$fileName = "Request_" . $idRequest . "_Update.xls";
$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save($fileName);
$objPHPExcel = PHPExcel_IOFactory::load($fileName);
echo json_encode(array(
"ExitCode" => 0,
"Message" => "Success",
"data" => $request,
"File" => "../reports/$fileName"
));
Once i receive File
in the $.ajax
call that receives it just add it to an anchor tag:
$.ajax({
...
success : function(response){
$('#container').append('<a href="'+response.File+'">Here is your file</a>
}
Solution
The accepted response to this question shows how to handle a success response be offering the file for download, or a failure response handled by the js (e.g. displayed within the current html page) without mime type issues
Answered By - Mark Baker Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.