【问题标题】:Avoiding Request Url Too Long with PHP for a file XLS Relay Service使用 PHP 避免文件 XLS 中继服务的请求 URL 过长
【发布时间】:2012-05-17 20:57:00
【问题描述】:

我正在尝试做的是提供一种下载在 js 客户端生成的 Xls 文件的方法。所以我在 js 中有一个字符串中的 xls,需要给用户一种下载它并在 excel 中打开它的方法。

据我所知,这样做的唯一方法是通过内容类型在服务器上执行此操作,因此我尝试提供一个执行文件中继的 php...这是 php

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.csv\"");
$data=stripcslashes($_REQUEST['csv_text']);
echo $data; 
?>

一个请求最终可能会很长,例如我可能有这个请求...(实际上大大缩短了)。

我不擅长 php,谁能建议一个更好的方法来修改这个中继脚本(或完全更好的方法)来完成这个?

http://myserver.com/ExcelRelay.php?csv_text=Id%09City%09Phone%09Address%201%09Address%202%09State%09Type%09Employees%09Revenue%09Leed%09Established%09Comments%09Country%09Postal%20Code%09Territory%0A3%09Greensboro%096538227668%09%0978%20Rocky%20Second%20St.%09New%20Jersey%09Remote%09%090%091%09Sun%20Aug%2009%201964%2000%3A00%3A00%20GMT-0400%20%28Eastern%20Daylight%20Time%29%09%22Et%20quad%20estis%20vobis%20homo%2C%20si%20nomen%20transit.%20%0A%20Sed%20quad%20estis%20vobis%20homo%2C%20si%20quad%20ut%20novum%20vobis

感谢您的回复,最终脚本是

<?php header("Content-type: application/octet-stream"); 
     header("Content-Disposition: attachment;filename=\"".$_POST['filename']."\"");    
     echo $_POST['data']; 
 ?>

【问题讨论】:

    标签: php javascript export xls


    【解决方案1】:

    一个字:POST

    Request Url Too Long 是客户端错误,并且是(AFAIK)IE 独有的错误,这些天。如果您想将数据发送到服务器并将其作为文件发送回您,则必须在请求正文中发送数据。

    更多信息请参见here

    【讨论】:

    • 谢谢,最终的 php 脚本是:&lt;?php header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$_POST['filename']."\""); echo $_POST['data']; ?&gt;
    猜你喜欢
    • 2014-12-22
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    • 2011-09-19
    • 2017-07-21
    • 1970-01-01
    相关资源
    最近更新 更多