Javascript handling of php readfile octet stream

solosapa

New Member
OK, I've had a good read through the "Related Questions" section and I haven't found this answer. I'm using an ajax request to force a php download. Things are working fine on the PHP end. Let's say I've got a stream of data called \[code\]DATA\[/code\]. Now, I want to pop up a "Save as..." dialog. The browser has received a string of hex values. Now, what do I do with this \[code\]DATA\[/code\] on the client (javascript) side?This is the PHP code that I'm using, per the link above:\[code\]header('Content-type: application/octet-stream');header('Content-Disposition: attachment; filename=$file');readfile($file);\[/code\]I've tried
  • window.open(\[code\]DATA\[/code\]) -> hex stream doesn't exist (of course)
  • submitting a form with the action as \[code\]DATA\[/code\] -> same problem
BTW, If I echo the file from PHP then use window.open, it works sometimes. But not for txt files or jpgs etc.I've seen this working on other sites - how are they doing it? Thanks in advance.
 
Back
Top