Forum Moderators: coopster
How do I:
A: Allow the button to be clicked and the form fields to be sent to a PHP without the screen trying to refresh to a new page.
B: From that background script, get PHP to send a file from the server to the user, again without refreshing to a new page. Instead it would just bring up a file requester to allow the user to save the file.
[edited by: coopster at 3:00 pm (utc) on Jan. 5, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]
At least, is it possible for a PHP script to send a file to the user, and if so, how. I've looked on Google for a while, and didn't seem to find a solution.
Jatar_k: When I said refresh, I meant no changing of the current page. It's so that the user can submit new variables and get another file later, without having to use the back button in the browser.
problem is that to send information to the server it needs to actually send it
once you client has gotten the page (initial GET request) they will need to POST their info to the server and this will go to another script, normally, and that script will then send something back
you can then do all the things you want to and then redisplay the form if you like
I'll try the AJAX solution, but if I have no luck with that, then I'll try the redisplaying of the form.
sprinkles: Hope you got my stickymail, only WebmasterWorld says there's nothing in the outbox.
Oh I still need to know how I can get PHP to send the user a file...
Since you are only using the iframe to return a download prompt, the iframe could be styled (using CSS) to be 1px by 1px and positioned off the page.
This gives the appearance of "no refresh" without dependence on javascript (without AJAX).
Send the right header [php.net] (Content-Disposition) and the browser should show a save dialog.
I've been playing around with stuff like this:
header("Content-Type: audio/x-midi");
header("Content-Disposition: attachment"); // (tried inline too)
header("Location:$outname");
In this case, a requester appears which is great, but as soon as the file is opened or is saved, the Explorer window immediately closes, and therefore doesn't display the HTML code I want people to see.
It turns out you can get rid of the first two lines completely, so you're just left with:
header("Location:$outname");
Again, I have the same problem.
It turns out you can get rid of the first two lines completely
Hmm, depends on the browser and how the user has set up their mime-type handling. Best to leave your "this is a download" headers intact.
So, the download works, but now you want to show HTML after the file is done downloading? Or just while it's downloading?
So, the download works, but now you want to show HTML after the file is done downloading? Or just while it's downloading?
Either will do actually. As long as if they 'cancel' or close the requestor*/save window, the html will still then display.
(* NB. The 'requestor' term I used is the window which says "would you like to open or save this file?")