SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP to Download Multiple Files with One Click

    Hi: I have a MySQL database that stores, for each record, the address of a file available for download. Using PHP, it's quite easy to have a search utility that returns a hyperlink to the download file for each record that matches the search.

    But there's a twist! I need to give the user the option to click on a single link that will download ALL of the files that correspond to the matching records from the search if he so desires. Whether I use PHP to create an archive (Zip?) on the fly, or whether it would just be a succession of individual file downloads doesn't really matter. But my client doesn't want the user to have to click on each and every link if he chooses to download all of the files. Obviously I can't archive them ahead of time, because the collection of files would be dependent upon the search criteria. Any ideas?

    Thanks!

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, actually it could be quite easily done.
    Have your script output a series of frames, with each frame source pointing to the url of the file you want to be able to let users download. However, in this case, the downloads would appear quickly and the visitor have to accept each download, and if his computer isn't strong enough to support the number of downloads that his query had sent, it might just crash his computer.

    Just a way is to use frames anyway.

  3. #3
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or refresh the page via meta for all the downloads.

    Here is all I can find on zips, and it doesn't include writing to them, just reading them.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would look into zlib, it can be compiled into PHP, if that is an option, with it you can create compressed archives on the fly.

    www.php.net/zlib

    This way you can create an array of the filenames for download, create a compressed archive of the files, and then send the appropriate header information to allow the user to download the stream in one fast swoop.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Creating the ZIP file on the fly is pretty much the only solution. Even online file storage companies like the now-defunct iDrive would present a series of links for each file to be downloaded individually.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  6. #6
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I do that? In researching PHP.net, it appears that I can't write an actual zip file, I can only perform "read" functions on zip files. And I can use zlib to create gzip files on the fly, but a gzip archive can't contain multiple files! (That last bit is from the Help within WinZip).

    Is this not correct?

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hmm looks like you're right. You may have to use PHP's system or exec function to execute a zip program externally to compress the files...
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  8. #8
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another option that I'm now trying is simply sending an e-mail with an attached file for each record in the search results. It's not as good as having a single archive file, but in theory it would at least allow me to accomplish what I'm trying to do. I'm just replacing the concept of a download with an e-mail instead.

    I've used PHP's mail function before, but I've never attached a file. I tried some of the user-supplied suggestions from PHP.net, and I couldn't get them to work. Is there an easy way to tell PHP to attach a file from the web server to the e-mail message that it sends out?

    Thanks, as always, for your help!

  9. #9
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mail()

    As far as I know you must go a either use, or make, a function that goes to send mail directly and talkwith it to attach files etc. Mail() doesn't do that...as far as I know. There are some functions out there that can do this.....try:


    http://php.resourceindex.com/


    I am sure there is something there. Search for something like "mail and mime".
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out this if you haven't already
    http://www.heyes-computing.net/download.php?script_id=4
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    assuming unix - you can use zip - gzip did not work properly for me when adding to an archive, so...

    <?
    $str="file1.yak";
    system("zip -r bigzip $str");
    ?>

    would create bigzip.zip, and imagining an array containing the selected downloads..

    <?
    for($x=0;$x<count($file_array);$x++){
    system("zip -r bigzip $file_array[$x]");
    }
    echo "<a href=\"bigzip.zip\" target=\"blank\">bigzip</a>";
    ?>

    note that system() echo's returned info to the screen , if you do not want that use exec().


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •