dongtou2016 2014-05-12 20:18
浏览 84
已采纳

在表单中传递PHPExcel对象[关闭]

Is it possible to pass a PHP phpexcel object into a page's HTML so I can pass it back to the server with a form POST or in an ajax call using jquery or something? I create the object when I'm generating an html table view of the data and I want them to be able to click on a button and download it as a document if they want it, but I want to be able to use the object I already created to produce the download document for them.

Can I pass the object to the client in the HTML and then pass it back to the server?

  • 写回答

1条回答 默认 最新

  • doupa1883 2014-05-12 21:16
    关注

    Typically what I do in these scenarios is one of the following:

    1) Generate and save the information as a document at the same time as I generate the page to display to the user. Then, when they want to download it, I link directly to the file I just created. This is appropriate when it's a low volume page that maybe one person or a handful of people will be accessing once a day, and they have a high probability of downloading the file every time they use it. This is usually the scenario I find myself if when generating these sorts of documents. Just make sure you manage your documents so they don't pile up, probably by overwriting existing documents with the most recent document every time you generate it, or otherwise by deleting old documents.

    2) When they click to download, just re-generate the data with the same queries. This is appropriate if the queries are fast and the data doesn't change much, or it doesn't matter if the data that they download is slightly updated from the data they see on the page.

    3) When generating the data for the page, save it to the user $_SESSION, which should (for most objects, at least) serialize it and unserialize it appropriately for future access. If PHPExcel doesn't handle this well, you'll probably want to create your own class that inherits from PHPExcel and use __sleep() and __wakeup() to appropriately manage any details you need to make sure it serializes and unserializes appropriately. Then when you make your call to download the data, you can use the data in memory just like you had just created it. You may want to actively manage your user session to make sure it doesn't sit in there taking up a bunch of memory each time the user requests a page, if it's a fair amount of data.

    The last option is probably the most "correct" approach, and is likely to be appropriate for most scenarios. A serialized PHP object has no business being stored in an HTML form to be passed back to the server, at least not under any normal circumstances.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接