Javascript octet stream php readfile

Well, I read the "Questions on the topic" section well, and I did not find the answer.

I am using an ajax request to force php to load . Everything works fine at the end of PHP. Say I have a data stream called DATA . Now I want to open the "Save As ..." dialog.

The browser received a string of hexadecimal values. Now, what should I do with this DATA on the client side (javascript)?

This is the PHP code I'm using, from the link above:

 header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename=$file'); readfile($file); 

I tried

  • window.open ( DATA ) -> hex stream does not exist (of course)
  • represents a form with an action like DATA same problem

BTW. If I repeat the file with PHP, then use window.open, it works sometimes. But not for txt files or jpg, etc.

I saw how it works on other sites - how do they do it? Thanks in advance.

0
source share
1 answer

Here is the answer I was looking for:

 window.open("downloadPage.php"); 

... a window appears every time. The problem with the ajax request was that the returned file stream was interpreted as XMLHttpRequestObj.reponseText .

The browser seems to interpret this differently and does not allow downloads.

0
source

All Articles