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?
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.
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.
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.
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).
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?
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:
I am sure there is something there. Search for something like “mail and mime”.