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 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧