Jump to content

Recommended Posts

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

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 by phppup
Typos

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.