1

What i am trying to do is provide a way for an Xls file generated on the client side in js to be downloaded. So I have the xls in a string in js and need to give the user a way to download it and open it in excel.

As i understand the only way to do this is to do it on the server via the content type, so I have tried to provide a php that does a file relay... Here is the php

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

A request can end up being rather long so for example i might have this request... (actually shortened greatly).

I am not good with php, can anyone suggest a better way to modify this relay script (or better way entirely) to accomplish this?

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

Thanks For the Response, The final script was

<?php header("Content-type: application/octet-stream"); 
     header("Content-Disposition: attachment;filename=\"".$_POST['filename']."\"");    
     echo $_POST['data']; 
 ?>
Tim
  • 3,576
  • 6
  • 44
  • 58

1 Answers1

3

One word: POST.

Request Url Too Long is a client side error, and one that is (AFAIK) exclusive to IE, these days. If you want to send the data to the server and have it sent back to you as a file, you will have to send the data in the body of the request.

See here for more information.

Community
  • 1
  • 1
DaveRandom
  • 87,921
  • 11
  • 154
  • 174