doushichi3678 2015-10-28 09:33
浏览 30

如何通过AJAX-Call启动下载或使用SlimPHP在服务器上保护文件?

I am developing an AngularJS WebApp with SlimPHP as Backend.

I implemented a basic Token-Authentication (custom HTTP - header "x-myapp-auth"). The token is validated by my "User" middleware on every state change in the app via an AJAX-Call. There is the need for converting some JSON - Data to XLS, which I do on the server side within SlimPHP.

Now to my question: How can I

  1. either secure my XLS files on the Server with my Auth-Token in Slim so that I can have a default download href to it in my app
  2. make the Browser recognize I want to initiate a download, when I open a "XLS Stream" (sorry, I don't know how to describe it better) from my route in SlimPHP.

The output code for (2) would be:

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$jsonData->title.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

But when I retrieve that output via AJAX, I can't make the browser initiate a file download.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算