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.


I thought the php script would still do the downloads via browser even if it was called by the JS.

PHP can’t “do” anything in the browser. It runs on the server. Only its output is ever even seen by the browser.

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

JS runs in the browser, and (as noted above) PHP runs on the server. No, they can never “work together.” You can use AJAX to communicate between JS and a PHP script, but remember that the PHP script will run fresh on each request.

This about it this way:

On the server, you HTML, CSS, and JS doesn’t exist yet. PHP sees those things as “just text.”

On the browser, your HTML and CSS are parsed, and your JS runs. At this point, PHP doesn’t even exist anymore.

Looks like I got more research to do!

This will always be true, so learn to enjoy it. : )

I’m bad a recommending tutorials, mostly because they’re a waste of time for me. I learn from reference materials. On that note, MDN(for HTML, CSS, and JS) and PHP) are indispensable reference sites.

I will recommend that you check out phptherightway, and that you stay away from w3schools. For HTML/CSS/JS, go to youtube and search for the “google code from the ground up” series.

Btw, are HTML5 websockets a good replacement for AJAX?

You can use them for many of the tasks you might otherwise use ajax for, but you need a server that handles persistent connections. Websockets are a lot of fun in node js. I’ve read that it is possible to handle web sockets in PHP, but I’m not sure I believe that (or that it would be at all efficient/ worth the hassle).

For what you’re doing, ajax would be better regardless.