1

Hello there okay so this is the deal i have a folder where my mp3 files are stored for single download, and now i want a feature where you can download all the mp3s at once in a zipped folder. Is it possible to zip all the files from that folder using php ( or anything really but if not PHP then please explain thoroughly) or would i have to just re-upload all the mp3s again in zipped format?

Thanks you so much.

DonJuma
  • 2,028
  • 13
  • 42
  • 70
  • Have you checked http://uk3.php.net/manual/en/book.zip.php – Rwky Oct 19 '10 at 20:17
  • Possible duplicate of [Open file, write to file, save file as a zip and stream to user for download](http://stackoverflow.com/questions/2286639/open-file-write-to-file-save-file-as-a-zip-and-stream-to-user-for-download) http://stackoverflow.com/questions/953996/php-zip-3-small-text-files-and-force-download and others. – Dave Jarvis Oct 19 '10 at 20:27

3 Answers3

6

Just to demonstrate use of the undocumented addGlob() method of the zipArchive class:

$zipFile = dirname(__FILE__)."/myMP3s.zip";
$zipArchive = new ZipArchive();

if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE))
    die("Failed to create archive\n");

$zipArchive->addGlob(dirname(__FILE__)."/*.mp3");
if (!$zipArchive->status == ZIPARCHIVE::ER_OK)
    echo "Failed to write local files to zip\n";

$zipArchive->close();
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
0

There are several PHP libraries for compression. Have you tried them?

Harmen
  • 22,092
  • 4
  • 54
  • 76
0

http://php.net/manual/en/book.zip.php

Mark Baker's example looks good, read up if you want to learn or need something more specific.

jon_darkstar
  • 16,398
  • 7
  • 29
  • 37