Page 1 of 1

providing multiple file download for site user

Posted: Wed Dec 29, 2010 5:02 am
by divedj
I am working on a photo website and would like to provide users with the possibilety to download multiple images out of a shopping basket like configuration.

Since I am dealing with large original image files any attempt to create a zipped archive using zlib fales soon as there are more than 4 to 5 files in the cart due to server load limitations etc.

Using simple http headers works fine for providing a single file download.

Code: Select all

Header("Content-type: application/octet-stream");
            Header ("Content-disposition: attachment; filename=archive.zip"); //filename could be any sample.txt or sample.jpg
            echo $zip->file(); //in this case the link to the file pulled out of a compression class
Trying to implement a loop going through a list of files stops after the first file downloaded.

Code: Select all

                   
                   if(ini_get('zlib.output_compression'))ini_set('zlib.output_compression', 'Off');

                    switch($fileExtension)
                    {
                        case "gif" : $ctype = "image/gif"; break;
                        case "png" : $ctype = "image/png"; break;
                        case "jpg" : $ctype = "image/jpg"; break;
                        case "jpeg" : $ctype = "image/jpeg"; break;
                        default : $ctype = "application/force-download";

                        session_cache_limiter("");

                        header("Pragma: public");
                        header("Expires: 0");
                        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                        header("Cache-Control: private", false);
                        header("Content-Type: $ctype");
                        header("Content-Disposition: attachment; filename=".basename($sourceFile).";" );
                        header("Content-Transfer-Encoding: binary");
                        header("Content-Length: ".filesize($sourceFile));

                        $file = fopen($sourceFile, "rb");

                        if($file)
                        {
                            while(!feof($file))
                            {
                                print(fread($file, 1024*8));
                                flush();

                                if(connection_status() != 0)
                                {
                                    @fclose($file);
                                    die();
                                }
                            }
                            @fclose($file);
                        }
                    }
   
I would be very happy if anybody knows a working solution to it. Thanks

Re: providing multiple file download for site user

Posted: Thu Dec 30, 2010 4:02 am
by Darhazer
Only one file can be downloaded with one request.
You can use flash downloader to allow simultaneous downloads. I've never used, but MySpace had provided such solution for downloading mp3 files, so you can google for some open-source solution. Or you can change your hosting provider.

Re: providing multiple file download for site user

Posted: Thu Dec 30, 2010 5:48 am
by divedj
Thanks,
but this doesn't solve the problem. I am trying to give site users the possibilety to download the content of a shoppingcart in my case original sized images to their computer without putting additional software on their machine.

Since looping through through headers and even trying to cache the actual file until download is finished befor the headers are resent to the browser endet up in the download stopping after the first image.

I have seen various systems working this way -> there must be a way of accomplishing it.

Again, I am open for any ideas.....

Re: providing multiple file download for site user

Posted: Thu Dec 30, 2010 5:53 am
by Darhazer
you can open in new windows or iframes the files for download, so the user will be prompted multiple times to save the file.
but there is no way (other then using flash downloader or java applet) to download multiple files with single http response (actually flash downloader will perform multiple requests/responses as well, but will prompt user for save location just once)
If you have seen such systems, go see how they are implemented. Capture the http traffic and see if they have multiple requests and responses, if they use some client-side technology as flash or java, etc.