The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End php download multiple files problem. Reply To: php download multiple files problem.


No problem. I wasn’t thinking very clearly in my earlier answer. Ajax can request the URL, but it has no way of handling the download (the browser must do that).

No worries __. :) I can easily see how this is a lot of information to learn and remember and how if one hasn’t been doing it recently things can get forgotten/hazy. Much appreciate your help.

I think that explains why when I used an alert in the JS it showed a bunch of garbage. Must of been the binary file. So what I’m guessing here is that the php script is sending back the binary download data to the calling JS? I didn’t know that. I knew if I had php echo text back to the JS, the JS would get it but I thought I could have JS send the list of image filenames to the php script that the php script would then do the downloads without sending the binary data back to the JS script. Requiring data round trip seems like a bad design to me, oh well.

So to be clear here you’re saying that won’t work because php is actually trying to send the files to the JS and JS has no way of handling them? Strange. I thought the php script would still do the downloads via browser even if it was called by the JS.

Is there a way to have Javascript and php in the same page where they work with each other?

There are two general approaches (both of which can be managed via javascript).

set the download URL as the src in an iframe on the page.
I’ve done the second but not in some time. I remember it worked well. I’ll do a refresher and let you know tomorrow. IIRC, your PHP script won’t need to change.

That would be fantastic!
Looking forward to your help :)

open a new window with the download URL. This is very easy and reliable, but can get tripped up by popup blockers.

I would prefer not to open a new window but I am curious how to get that done just so I know in the future should I need it.

Instead of me scouring the internet and hurting my eyes can anyone recommend a great book, website or video lessons to learn all this stuff ? AJAX, HTML5 websockets, etc?
I’m still very new to all of this web coding stuff.

Looks like I got more research to do!

Btw, are HTML5 websockets a good replacement for AJAX?
Is there a way to update pages without reloading them using HTML5 websockets and Javascript or CSS?

It’s hard to find a complete book (or website) that covers all of these languages working together.