Use two different headers for two different exits in the same call

Asked

Viewed 60 times

0

At a certain point, I need to generate XLS files on my system, and use the following header for output:

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $name[$a] . '.xls"');
header('Cache-Control: max-age=0');

But, I don’t use the answer of this method, I need the answer of another method that should return a json, I’m trying:

header('Content-type:application/json;charset=utf-8');
echo json_encode($response);

I set this header after calling the previous headers ('vnd.ms-excel') and used them, but the answer does not take this second definition, it always returns me with the encoding to 'vnd.ms-excel'.

How to use a header to generate a . XLS and a second to return a json in the same call?

  • I don’t know if I got it right... but do you want an answer to contain two different types? This is only supported as upload (using Multipart Types), now replies cannot have more than one type as far as I know. If you’re returning one header('Content-Type: application/vnd.ms-excel'); you are saying that the return is a vnd.ms-excel'. There is no way a browser can handle two types of data in one request. For example, you can’t say that a response is an image and a JSON at the same time, either it’s one or it’s another.

  • So, I make a request, build an XLS (or several) and save them in a directory, in this part I need the header vnd.ms-excel, but I check if he saved the file and then I need the answer in json, to tell the client whether or not he managed to save the files

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.