I need the ability to download more than one large file at the same time from the same php page. Is there a php function, core or 3rd party, that allows this, or is there another way of doing it?
I have tried initiating the download outside of a session each time, I have tried initating the download in a popup window, in a new window, and on a new php page, and nothing works when the link originates from the same page. I have also tried various http headers, such as "Connection: close" and this doesn't help. The only time I can download more than one file at the same time on my page is if I start a new Internet Exporer window from my desktop of that page, and do it from there. Then a simultaneous download of another file from that same page is possible. I am currently using print get_file_contents("path-and-filename") (which is the equivalent of readfile() but readfile() is disabled by my host).
Is there any way of allowing the download of multiple files at the same time when the download links originate from the same page, without starting another Internet Explorer window manually, and without having to open a duplicate of that same page?
Regards,
N
I still can't do simultaneous downloads!
Moderator: General Moderators
-
Navigateur
- Forum Newbie
- Posts: 2
- Joined: Tue Feb 05, 2008 5:36 am
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: I still can't do simultaneous downloads!
You can't do this with HTTP -- you only get one response. You could zip up all the files on the server side and send the zip file to the client.
(#10850)
Re: I still can't do simultaneous downloads!
You cant. I'm not sure if you could simulate two pages using html's iframes, but from one php-page alone, no.
In theory, you could initiate a popup/down calling on a script to send file A, while the page itself is sending file B. It could both be the same file but the difference could be in the URI being used;
Mainpage; http://www.example.com/filesend.php
Popup; http://www.example.com/filesend.php?file=B
Hope I made sence.
In theory, you could initiate a popup/down calling on a script to send file A, while the page itself is sending file B. It could both be the same file but the difference could be in the URI being used;
Mainpage; http://www.example.com/filesend.php
Popup; http://www.example.com/filesend.php?file=B
Hope I made sence.
-
Navigateur
- Forum Newbie
- Posts: 2
- Joined: Tue Feb 05, 2008 5:36 am
Re: I still can't do simultaneous downloads!
No, I can!
This is how I did it
1. Instead of readfile() or print file_get_contents(), I used fopen() and fread() as follows:
(This is after all the header()s for Content-disposition, Content-type, Content-length etc.)
2. I made sure that this was executed outside of a session. So I removed session_start() from the top of the page and did some tweaking so I would not need to use session variables directly on the "download.php" page. And voila! Simultaneous downloads limited only by Internet Explorer's MaxConnectionsPerServer registry setting.
3. One more thing: if you have ob_start() at the top of your page, which I had so I could dynamically create cookies in the middle of the code, insert ob_end_clean(); before your http headers of the file, otherwise the download starts very slowly.
I also read elsewhere that this was not possible, but cracked it finally.
I would love to hear if anyone benefits from this tip.
Regards,
N
This is how I did it
1. Instead of readfile() or print file_get_contents(), I used fopen() and fread() as follows:
Code: Select all
if ($file = fopen($myfilepathandname, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
print(fread($file, 1024*8));
flush();
}
fclose($file);
}2. I made sure that this was executed outside of a session. So I removed session_start() from the top of the page and did some tweaking so I would not need to use session variables directly on the "download.php" page. And voila! Simultaneous downloads limited only by Internet Explorer's MaxConnectionsPerServer registry setting.
3. One more thing: if you have ob_start() at the top of your page, which I had so I could dynamically create cookies in the middle of the code, insert ob_end_clean(); before your http headers of the file, otherwise the download starts very slowly.
I also read elsewhere that this was not possible, but cracked it finally.
I would love to hear if anyone benefits from this tip.
Regards,
N