M.O.S. Studios Posted 16 hours ago Share Posted 16 hours ago Hey guys, I have a script I’m working on, and I was curious if I can do the following: 1. user clicks button on browser, that sends a request to the server using ajax 2. the server creates a zip file and stores it in php://memory 3. the browser get the needed information to initiate a download of the zip file. can this be done? I suspect I have to physically save the file on the server, and delete it after; which I would like to avoid Quote Link to comment https://forums.phpfreaks.com/topic/327291-download-a-dynamically-made-file-as-part-of-ajax/ Share on other sites More sharing options...
requinix Posted 13 hours ago Share Posted 13 hours ago Why use AJAX at all? Simply send the browser to the "page" which (immediately) serves the download. Quote Link to comment https://forums.phpfreaks.com/topic/327291-download-a-dynamically-made-file-as-part-of-ajax/#findComment-1652831 Share on other sites More sharing options...
phppup Posted 13 hours ago Share Posted 13 hours ago (edited) Looks like requinix responded while I was considering my answer, which would be a YES. ITEM 1 is easy enough. ITEM 2 would require some research (for me, anyway) but should be do-able since PHP can go to a directory and find the file you want to use. ITEM 3 can also be done. I forget the methodology, but I did create a page that allowed me to download files from <a> links; a few modifications and your requirements would be met. As for wanting to NOT have the file on the server, did you want PHP to write the script and ZIP it every time it's needed? I suppose it could be done, but a cumbersome way of making sure nobody sees the script on the server, yet they can grab it through the browser. Edited 13 hours ago by phppup Typos Quote Link to comment https://forums.phpfreaks.com/topic/327291-download-a-dynamically-made-file-as-part-of-ajax/#findComment-1652832 Share on other sites More sharing options...
maxxd Posted 12 hours ago Share Posted 12 hours ago Most systems I've seen will write the file to a temporary directory on the server, zip it and serve the zip to the user, then delete the file from the temporary directory. But honestly requinix is right - just direct the user in a new tab to the page that gathers the data and presents it. If I'm not mistaken, the tab itself will close and your user will get the browser's download window. Quote Link to comment https://forums.phpfreaks.com/topic/327291-download-a-dynamically-made-file-as-part-of-ajax/#findComment-1652835 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.